dsh-modpack-kit 0.1.5 → 0.1.7-1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,9 +1,10 @@
1
1
  # dsh-modpack-kit(DSH 整合包)
2
2
 
3
- 为 DeepSeek Harness 提供类似 HMCL / PCL 的「我的世界整合包」打包与安装能力:把多个插件连同各自的配置与数据打成一个 `.dshpack`,一次安装到位。
3
+ 为 DeepSeek Harness 提供类似 HMCL / PCL 这类「我的世界启动器」的整合包打包与安装能力:把多个插件连同各自的配置与数据打成一个 `.dshpack`,一次安装到位。
4
4
 
5
5
  - **懒人包与轻量包**:懒人包(完整包)自带插件本体,目标机器只需安装 DSH 本体,按包内 `README.txt` 或 `install/` 独立安装器即可完成安装;轻量包只记录插件名与版本,安装时按记录从插件市场取包,体积更小。两种包都附独立安装器。
6
6
  - **逐插件定制**:每个插件单独选「基础配置」(上游原版代码 + 插件默认配置)或「本地改动」(本机的代码、配置条目、数据快照),同一个整合包里可以混用。
7
+ - **只列真正的插件**:一个插件自带内部组件时(例如壁纸引擎把组件发成了独立包),只列父包,内部组件随父包一起安装,不会被重复打包或重复安装。
7
8
  - **配置与数据保真**:配置按原结构回填到 `cordis.patch.yml`,只改目标条目、其它字节保留;数据快照写回 `~/.dsh/<目录>/`,默认不覆盖本机已有文件。疑似凭据替换为 `${REDACTED}`,其余自定义项原样保留。
8
9
  - **打包前强制检测**:对敏感信息与风险代码做静态扫描,命中只留掩码、原文不落盘;高风险停在「等决定」,确认后在同一任务里从检测点续跑。安装前再校验 sha256 完整性、兼容性与许可证。
9
10
  - **与插件市场同步版本**:分类、搜索、分页与条目来自市场目录(首屏只列已安装插件);本机插件若在市场有同名条目,可切换市场版本打包,联网安装时也可优先按市场版本取包。
@@ -36,7 +37,7 @@ dsh plugin --profile desktop add github:Vesna-Strivozha-cn/dsh-modpack-kit
36
37
  **联动的地方**
37
38
  - 目录同源:直接读插件市场自己的目录包 `dsh-plugin-catalog`(先走 CDN 的 `index.json`,取不到退回 npm tarball),23 个分区、条目数、排序规则都跟市场一致;市场没装也能用,只是少了它的界面。
38
39
  - 安装同路:都走 `dsh plugin --profile <p> add`,两边装的插件互相可见,不需要各记一份状态。
39
- - 已装插件会用目录补齐描述与分区,标出「市场版 vX」以及是否有更新;同名条目行末出现「(切换市场版)」。
40
+ - 已装插件会用目录补齐描述与分区,标出「市场版 vX」以及是否有更新;同名条目标为「本机 · 有市场版」,勾选时默认按市场版打包,行末可用「(切回本机版)」改回本机那份。
40
41
  - 三处入口里「插件页内」那一栏,跟市场的 Discover 栏并排,互不占位。
41
42
 
42
43
  **有市场 / 没市场对照**
@@ -49,14 +50,14 @@ dsh plugin --profile desktop add github:Vesna-Strivozha-cn/dsh-modpack-kit
49
50
  | 侧边栏 / 设置里 / 插件页内三处入口 | ✅ | ✅ 一样(这些槽位是 DSH 核心声明的,不是市场插件) |
50
51
  | 分类胶囊、搜索、服务端分页 | ✅ | ✅ 只要建过一次目录索引就行(5~30 秒,看网络) |
51
52
  | 已装插件补齐描述、分区、市场版版本 | ✅ | ✅ 建过索引后一样 |
52
- | 「(切换市场版)」按上游原版打包 | ✅ | ✅ 建过索引后一样 |
53
+ | 有市场版时默认按上游原版打包 | ✅ | ✅ 建过索引后一样 |
53
54
  | 轻量包安装时按版本取包 | ✅ | ✅ 只要有 npm registry 网络 |
54
55
  | 市场 Discover 栏、市场自己的更新入口 | ✅ | ❌ 没有(用本插件或 `dsh plugin` 装同一个包即可) |
55
56
 
56
57
  **没索引、也没网时会怎样**(这种情况页面会明说,不会静默装错)
57
58
  - 首屏照旧只列本机已装插件,打包与安装不受影响。
58
59
  - 分类胶囊只剩「全部」,已装行的分类退回内置兜底规则,与市场 23 类的 id 不完全对得上——按 theme / memory 之类筛会漏几条。点「建立目录索引」跑一次就恢复。
59
- - 搜索、市场版版本对比、「(切换市场版)」按钮不出来。
60
+ - 搜索、市场版版本对比、市场版/本机版的切换按钮不出来(此时只能打包本机那份)。
60
61
  - 轻量包装不了(它不带源码,必须联网按清单里的版本取包);完整版照装。
61
62
 
62
63
  ## 分类、搜索与分页
@@ -64,7 +65,7 @@ dsh plugin --profile desktop add github:Vesna-Strivozha-cn/dsh-modpack-kit
64
65
  - 分类就是插件市场的 23 个分区(全部 / AGI 架构探索 / UI 增强 / 用量与计费 / 主题与外观 / 模型与账号接入 / 身份与通信 / 会话与消息 / 记忆 / 工具与能力 / WSL 与 Windows 互操作 / 浏览器与网页 / 视觉与多模态 / 语音与音频 / 文档与渲染 / 技能包 / 工作流与自动化 / Git 与代码评审 / 通知与集成 / 开发与运行时 / 安全与权限 / 远程与移动端 / 插件市场与管理 / 娱乐),名字和条目数都从市场目录里读。
65
66
  - **首屏只列本机已装的插件**,不联网、不卡顿。搜索框右侧提供「全部加入」(一次选中本机已装全部插件,均按「基础配置」)与「清除选择」。输入关键词或点分类才去目录里搜,结果是服务端分页,一页 20 条(设置里可改),底部「加载更多」再取下一页。
66
67
  - 排序照抄市场的规则:**已装优先**,再按相关度(整字段命中 > 包含 > 其它词;包名权重最高,其次所有者、仓库,描述与分类最低),同分保持目录原序。本机独有、目录里没有的插件也能被搜到。
67
- - 本机已装的插件如果在目录里有同名条目,行末会显示小字「(切换市场版)」:选择后改用上游原版代码 + 默认配置打包,结果与从插件市场安装一致;再选一次「(切回本机版)」恢复本机快照。同名不代表一定是同一个插件,因此默认仍打包本机那份。
68
+ - 本机已装的插件如果在目录里有同名条目,行末会显示小字「(切换市场版)」:选择后改用上游原版代码 + 默认配置打包,结果与从插件市场安装一致;再选一次「(切回本机版)」恢复本机快照。默认按市场版打包:本机已装且有同名条目的插件,勾选时就走市场版本,避免把本地开发版带进包、装到别人机器上。要打本机那份,点「(切回本机版)」再选「本地改动」。同名可能只是撞名,切回本机版即按本机快照打包。
68
69
 
69
70
  ## 显示位置(三处独立开关)
70
71
 
@@ -155,7 +156,7 @@ ELECTRON_RUN_AS_NODE=1 "$EXE" dev/tools/verify.cjs
155
156
 
156
157
  搜索框在插件市场目录里查到的条目,**本机没装也能直接勾选打包**:这类条目打的是「市场来源」——打包时按版本从 registry 取包(默认取那一条的当前版本,想钉别的版本就在版本框里写),包内清单记 `source: "npm"`,安装时同样从市场按版本下载。
157
158
 
158
- - 「本机 / 市场 · 未装」标签区分来源;已装的行才有「基础配置 / 本地改动」与「(切换市场版)」。
159
+ - 「本机 · 有市场版 / 本机 / 市场 · 未装」标签区分来源;有市场版的默认按市场版打包,切回本机版后才出现「基础配置 / 本地改动」。
159
160
  - 没装的插件没有本机代码可打,所以永远是「基础配置」语义(上游原版 + 插件默认配置)。
160
161
  - 许可证仍按允许列表校验:市场条目的 license 不在列表里时,需要勾「我确认……有权再分发」才会出包。
161
162
 
@@ -242,13 +243,15 @@ node install/install.mjs --profile desktop --replace # 本机已装的也换
242
243
 
243
244
  ## 更新日志
244
245
 
245
- - **0.1.5(未发布)**:介绍与说明统一按「为 DSH 提供类似 HMCL / PCL 的整合包打包与安装」重写;补齐配置与数据快照的保真与回填(嵌套/数组/中文配置原样写回,空数组空对象不再写出非法 YAML,JSON 流式配置能读回原名;`data/` 快照首次支持安装写回 `~/.dsh/<目录>`,默认不覆盖本机已有文件);配置快照记录「哪些字段被擦」并随安装提示重填,数据快照也对明文凭据做替换(只留键名与 `${REDACTED}`)。
246
-
247
-
248
- - **0.1.4**:与 0.1.3 同一份代码,只是 npm 上 `0.1.3` 已被今天早些时候的旧版本占用,按语义化版本往上挪一档重发;GitHub 与 npm 从此对齐在同一版。
249
- - **0.1.3**:安装也走进度窗(与打包共用、可并行、可终止);安装时先跳过本机已装的插件,装完由用户选择「直接完成」或「替换为包内版本」;联网且市场有同名条目时优先安装市场版本。取包支持「选择文件…」「浏览文件夹…」与任意目录,「已导入的整合包」可同时留多份并显示打包时的名字/作者/描述。进度窗收尾自动收敛(`jobKeepSeconds` 默认 60 秒、失败十几秒、卡住十分钟判失败),「清空进程」改为乐观更新且不再和拖动/展开抢判定。打包支持市场里没装的插件(按版本从 registry 取包)。独立安装器加 `--replace`,并把插件复制到本机 vendor 后再登记。
250
- - **0.1.2**:市场已收录的插件出高危时改为「我已知晓其中风险」继续;去掉多余的「默认打包本机修改」全局勾选;加「全部加入 / 清除选择」;文案改书面语。
251
- - **0.1.1**:介绍补齐「与插件市场的联动」「有没有市场的区别」,并给出「建议先装市场、不装也能用」的说明。
246
+ - **0.1.7-1**(当前):代码与 0.1.7 相同,只为刷新 npm 上的说明文本重新发布(npm 不允许覆盖已发布版本的说明)。
247
+ - **0.1.7**:插件识别修正——内部组件不再被当成独立插件(支持多层依赖、scoped/别名、残包);市场来源固定先按市场版本安装,本机版有市场条目时同样如此,装完把包内本地改动覆盖回去;新增纯 DSH 兼容测试;修掉补丁层「注释 + `[]`」与「同 id 多条」两个坑;压缩等级按 64 KB 分档,HTTP 工具收进 `lib/http.mjs`。
248
+ - **0.1.6**:介绍口径统一为「我的世界启动器」;更新日志按版本汇总;插件页与设置页底部加项目地址与 Star 入口。
249
+ - **0.1.5**:配置与数据快照保真和擦除——空数组/空对象同行输出、`data/` 快照可写回 `~/.dsh/<目录>`、`configRedacted`/`dataRedacted` 记录擦除;安装优先走宿主 `pluginManager.installBundle`;扫描按内容去重、zip 跳过已压缩扩展名。
250
+ - **0.1.4**:与 0.1.3 同一份代码,仅版本号上移。
251
+ - **0.1.3**:安装进入任务队列与进度窗(可与打包并行、可终止);已装先跳过、装完可选替换为包内版本;新增独立安装器(裸 DSH 可装);风险按来源分组折叠,进度窗可拖动、空闲隐藏;清空进程、多份导入、打包市场里未安装的插件。
252
+ - **0.1.2**:高危一律先停在「等决定」;去掉全局「默认打包本机修改」;插件列表加「全部加入 / 清除选择」;提示改为书面语。
253
+ - **0.1.1**:打包页提示按是否安装插件市场分支显示;补与插件市场的联动说明。
254
+ - **0.1.0**:首个版本——`.dshpack` 双形态(懒人包 / 轻量包)、逐插件基础配置或本地改动、打包前强制扫描、安装前完整性与兼容性校验、配置按条目回填、市场目录分类搜索分页、三处入口独立开关。
252
255
 
253
256
  ## 目录
254
257
 
@@ -169,6 +169,12 @@ function readDependencies() {
169
169
  const installedBefore = readDependencies()
170
170
 
171
171
  for (const plugin of manifest.plugins || []) {
172
+ if (plugin.transitiveOf) {
173
+ // 父包会把它带进来:单独装一遍只会重复
174
+ results.push({ plugin, ok: true, skipped: true, message: '是「' + plugin.transitiveOf + '」的内部组件,随父包一起安装' })
175
+ say('跳过 ' + plugin.name + ':它是「' + plugin.transitiveOf + '」的内部组件,父包会一起装上')
176
+ continue
177
+ }
172
178
  const already = installedBefore[plugin.name]
173
179
  if (already && !replaceExisting) {
174
180
  // 需求:先跳过已装的,其余照装;装完再告诉用户怎么换
@@ -177,7 +183,7 @@ for (const plugin of manifest.plugins || []) {
177
183
  say('跳过 ' + plugin.name + ':本机已装 ' + already)
178
184
  } else {
179
185
  const dirName = plugin.dirName || plugin.name
180
- let spec
186
+ let fileSpec = ''
181
187
  if (manifest.format === 'full') {
182
188
  const dir = path.join(root, 'plugins', dirName)
183
189
  if (!fs.existsSync(dir)) {
@@ -185,32 +191,53 @@ for (const plugin of manifest.plugins || []) {
185
191
  continue
186
192
  }
187
193
  if (dryRun) {
188
- spec = 'file:' + dir.replace(/\\/gu, '/')
194
+ fileSpec = 'file:' + dir.replace(/\\/gu, '/')
189
195
  } else {
190
196
  const target = path.join(vendor, dirName)
191
197
  fs.rmSync(target, { recursive: true, force: true, maxRetries: 10, retryDelay: 200 })
192
198
  copyTree(dir, target)
193
- spec = 'file:' + target.replace(/\\/gu, '/')
199
+ fileSpec = 'file:' + target.replace(/\\/gu, '/')
194
200
  }
195
- } else {
196
- spec = plugin.name + '@' + plugin.version
197
201
  }
198
- const args = [...cli.args, 'plugin', '--profile', profile, 'add', spec]
202
+ const marketSpec = plugin.name + (plugin.version ? '@' + plugin.version : '')
203
+ // 需求:包里这份当初是从插件市场取的(source npm/market),安装时优先按市场版本装,
204
+ // 取不到(离线 / registry 上没有这个版本)再退回包内自带的那份。
205
+ const fromMarket = plugin.source === 'npm' || plugin.source === 'market'
206
+ const attempts = []
207
+ if (fromMarket) attempts.push({ spec: marketSpec, from: 'market' })
208
+ if (fileSpec) attempts.push({ spec: fileSpec, from: 'pack' })
209
+ if (!fromMarket && !fileSpec) attempts.push({ spec: marketSpec, from: 'market' })
210
+ if (attempts.length === 0) attempts.push({ spec: marketSpec, from: 'market' })
211
+ const runAdd = (spec) => {
212
+ const args = [...cli.args, 'plugin', '--profile', profile, 'add', spec]
213
+ if (dryRun) return { ok: true, output: '', args }
214
+ const res = spawnSync(cli.exe, args, {
215
+ encoding: 'utf8',
216
+ env: { ...process.env, CI: '1', ...(cli.env.ELECTRON_RUN_AS_NODE ? { ELECTRON_RUN_AS_NODE: '1' } : {}) },
217
+ shell: cli.shell === true,
218
+ maxBuffer: 32 * 1024 * 1024,
219
+ })
220
+ return { ok: res.status === 0, output: String(res.stdout || '') + String(res.stderr || ''), args }
221
+ }
199
222
  if (dryRun) {
200
- results.push({ plugin, ok: true, message: '演练:' + [cli.exe, ...args].join(' ') })
223
+ results.push({ plugin, ok: true, message: '演练:' + [cli.exe, ...runAdd(attempts[0].spec).args].join(' ') + (attempts.length > 1 ? '(失败则退回包内那份)' : '') })
201
224
  continue
202
225
  }
203
- say('安装 ' + plugin.name + '@' + plugin.version + ' …')
204
226
  const started = Date.now()
205
- const res = spawnSync(cli.exe, args, {
206
- encoding: 'utf8',
207
- env: { ...process.env, CI: '1', ...(cli.env.ELECTRON_RUN_AS_NODE ? { ELECTRON_RUN_AS_NODE: '1' } : {}) },
208
- shell: cli.shell === true,
209
- maxBuffer: 32 * 1024 * 1024,
210
- })
211
- const output = String(res.stdout || '') + String(res.stderr || '')
212
- const ok = res.status === 0
213
- results.push({ plugin, ok, message: ok ? '已安装(' + Math.round((Date.now() - started) / 100) / 10 + ' 秒)' : '失败:' + output.trim().split(/\r?\n/u).slice(-3).join(' | ') })
227
+ let last = null
228
+ let usedFrom = ''
229
+ for (const attempt of attempts) {
230
+ say('安装 ' + plugin.name + (plugin.version ? '@' + plugin.version : '') + '(' + (attempt.from === 'market' ? '插件市场版本' : '包内自带') + ')…')
231
+ const res = runAdd(attempt.spec)
232
+ last = res
233
+ if (res.ok) { usedFrom = attempt.from; break }
234
+ if (attempts.length > 1 && attempt.from === 'market') say(' 市场版本没装上,改用包内自带的那份再试一次')
235
+ }
236
+ const ok = Boolean(last && last.ok)
237
+ const message = ok
238
+ ? '已安装(' + Math.round((Date.now() - started) / 100) / 10 + ' 秒' + (usedFrom === 'market' ? ',市场版本' : usedFrom === 'pack' ? ',包内自带' : '') + ')'
239
+ : '失败:' + String(last && last.output || '').trim().split(/\r?\n/u).slice(-3).join(' | ')
240
+ results.push({ plugin, ok, message })
214
241
  say(' ' + (ok ? '完成' : '失败'))
215
242
  }
216
243
  }
@@ -231,8 +258,11 @@ function restoreConfigs() {
231
258
  }
232
259
  const id = String(snap.id || snap.name || name.replace(/\.json$/u, ''))
233
260
  let text = fs.existsSync(patchFile) ? fs.readFileSync(patchFile, 'utf8') : ''
234
- const trimmed = text.trim()
235
- if (trimmed === '' || trimmed === '[]') text = ''
261
+ // DSH 新建 profile 的补丁文件是「几行注释 + []」:只把 [] 当成空文档去掉,
262
+ // 否则追加会写出两份 YAML 文档([] 之后再跟 - id: …),整个文件就废了。
263
+ const bare = text.split(/\r?\n/u).map((line) => line.trim()).filter((line) => line !== '' && !line.startsWith('#'))
264
+ const emptyDoc = bare.length === 0 || (bare.length === 1 && /^(?:\[\s*\]|\{\s*\}|null|~)$/u.test(bare[0]))
265
+ if (emptyDoc) text = ''
236
266
  if (new RegExp('(^|\\n)\\s*-\\s*id:\\s*' + id.replace(/[.*+?^${}()|[\]\\]/gu, '\\$&')).test(text)) {
237
267
  say(' 配置条目已存在,保持本机原样:' + id)
238
268
  continue
package/client.js CHANGED
@@ -730,7 +730,9 @@ window.__ModuleLoader__.load({
730
730
 
731
731
  const picked = Object.keys(selected)
732
732
  // 市场里没装的插件也能打包:走 npm 源(安装时由市场按版本取包)
733
- const entrySource = (entry) => (entry.installed === false ? "npm" : "profile")
733
+ // 本机已装、但市场里有同名条目的,默认也走市场版:避免把本地开发版打进包、装到别人机器上
734
+ const entrySource = (entry) => (entry.installed === false || entry.hasMarket ? "npm" : "profile")
735
+ const entrySpec = (entry) => (entry.hasMarket ? entry.marketVersion || entry.version || "" : entry.version || "")
734
736
  const toggle = (entry) => {
735
737
  setSelected((prev) => {
736
738
  const next = { ...prev }
@@ -738,7 +740,7 @@ window.__ModuleLoader__.load({
738
740
  else next[entry.name] = {
739
741
  name: entry.name,
740
742
  source: entrySource(entry),
741
- spec: entry.version || "",
743
+ spec: entrySpec(entry),
742
744
  mode: "base",
743
745
  }
744
746
  return next
@@ -753,14 +755,14 @@ window.__ModuleLoader__.load({
753
755
  ...prev,
754
756
  [entry.name]: toMarket
755
757
  ? { name: entry.name, source: "npm", spec: entry.marketVersion || "", mode: "base" }
756
- : { name: entry.name, source: "profile", spec: entry.version || "", mode: "base" },
758
+ : { name: entry.name, source: "profile", spec: entry.version || "", mode: "local" },
757
759
  }
758
760
  })
759
761
 
760
762
  const addAllLocal = () => setSelected((prev) => {
761
763
  const next = { ...prev }
762
764
  for (const entry of localRows) {
763
- if (!next[entry.name]) next[entry.name] = { name: entry.name, source: "profile", spec: entry.version || "", mode: "base" }
765
+ if (!next[entry.name]) next[entry.name] = { name: entry.name, source: entrySource(entry), spec: entrySpec(entry), mode: "base" }
764
766
  }
765
767
  return next
766
768
  })
@@ -947,7 +949,7 @@ window.__ModuleLoader__.load({
947
949
  h("div", { style: { flex: "1 1 220px", minWidth: "180px" } },
948
950
  h("div", { style: label }, entry.title || entry.name, " ", h("span", { style: hint }, "@" + (entry.version || "?"))),
949
951
  h("div", { style: hint }, (entry.description || "").slice(0, 110))),
950
- h("span", { style: chip }, entry.installed === false ? "市场 · 未装" : "本机"),
952
+ h("span", { style: chip }, entry.installed === false ? "市场 · 未装" : (entry.hasMarket ? "已安装" : "本机")),
951
953
  h("span", { style: { ...chip, color: "var(--dsw-alias-label-tertiary)" } }, labelOf(categoryOf(entry))),
952
954
  entry.updateAvailable ? h(Tag, { color: "#2bb673" }, "市场版 " + (entry.marketVersion || entry.version) + " 更新") : null,
953
955
  on ? h("input", {
@@ -969,7 +971,7 @@ window.__ModuleLoader__.load({
969
971
  h("button", { style: btn, disabled: searching, onClick: loadMore }, searching ? "加载中…" : ("加载更多(还有 " + Math.max(0, search.total - rows.length) + " 条)"))) : null,
970
972
  h("div", { style: hint }, active
971
973
  ? "排序:已装的排前面,其余按插件市场的相关度与目录顺序。分类和词条都来自插件市场目录。"
972
- : "首屏只列本机已装。搜索或点分类才会去插件市场目录里查,服务端分页、一次一页。搜索结果里没装的插件也能直接勾选——打包时按版本从插件市场取包,装的时候同样从市场下载。")
974
+ : "首屏只列本机已装。插件自带的内部组件(随父包一起装的那种)不单独列出" + (props.status && props.status.installedHidden ? "(本次隐藏 " + props.status.installedHidden + " 个)" : "") + "。本机已装且市场里有同名条目的,勾选时默认按市场版打包(不打本地开发版);要打本机那份就点「(切回本机版)」,切回去默认按「本地改动」打(本机版通常带着自己的配置或改动)。搜索或点分类才去插件市场目录里查,服务端分页、一次一页。搜索结果里没装的插件也能直接勾选——打包时按版本从插件市场取包,装的时候同样从市场下载。")
973
975
  ),
974
976
  h("div", { style: { ...box, display: "flex", flexDirection: "column", gap: "8px" } },
975
977
  h("div", { style: strong }, "包选项"),
package/docs/DETAIL.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # 整合包(dsh-modpack-kit)
2
2
 
3
- 为 DeepSeek Harness 提供类似 HMCL / PCL 的整合包打包与安装:把多个插件连同配置与数据打成一个 `.dshpack` 一次装好,支持懒人包(完整包)与轻量包两种形态,并可按插件逐个定制打包内容、与插件市场目录同步版本。
3
+ 为 DeepSeek Harness 提供类似 HMCL / PCL 这类我的世界启动器的整合包打包与安装:把多个插件连同配置与数据打成一个 `.dshpack` 一次装好,支持懒人包(完整包)与轻量包两种形态,并可按插件逐个定制打包内容、与插件市场目录同步版本。
4
4
 
5
5
  ## 能做什么
6
6
 
@@ -8,6 +8,13 @@
8
8
  - 懒人包(完整版):插件文件一起装进包里;目标机器未安装本插件时,按包内 `README.txt` 或 `install/` 安装器即可完成安装。
9
9
  - 轻量包(轻量版):只保留名字、版本与来源,安装时按记录联网取包,体积更小但需要网络。
10
10
  - **逐插件定制**:每个插件单独选「基础配置」(上游原版代码 + 插件默认配置,不含本地改动)或「本地改动」(本机当前的代码、配置条目、数据快照)。全局开关只是新勾选时的默认值,勾上之后仍可逐个改。
11
+ - **只列真正的插件**:`lib/profile.mjs` 的 `listInstalled` 会读 profile `package.json` 声明的依赖,再看每个已声明包自己的 `dependencies`,把「由别的插件带进来的子包」标成 `isDirect: false` + `transitiveOf`(依据是父包名)。界面与 `/pack` 只认 `isDirect`;选择项里若出现子包会直接拒绝并提示「会随父包一起装上」。原因:有的插件把自己的组件也作为独立包发布(例如壁纸引擎的 `about-notice`/`fonts`/`fx`/`glass`/`mascot-avatar`/`media-bridge`/`parallax`/`pet-link`),按 `node_modules` 顶层目录罗列会让一个插件被当成九个,打包与安装都会重复。
12
+
13
+ - **安装后的市场版身份**:`source` 为 `npm` / `market` 的插件,安装时总是先走市场版本(不受 `preferMarketOnInstall` 影响);本机版插件若市场有同名条目,也按 `名字@版本` 安装(依赖清单里是市场版,插件市场认它是市场版而不是本地开发版),随后把包内载荷覆盖到 `node_modules/&lt;目录&gt;` 上并写「覆盖 N 个文件」;市场查不到才退 `file:` 本机副本。
14
+ - **纯 DSH 兼容测试**:`dev/tools/test-bare-dsh.mjs` 用真实 DSH 命令行 + 包内 `install/install.mjs` 装进新 profile(`--no-bundles`),核对依赖/`node_modules`/配置回填/`dsh plugin list`,并确认 desktop 未动;跑完自动删 profile、临时目录与本次 vendor。
15
+ - **空文档**:DSH 新建 profile 的补丁文件是「注释 + `[]`」。`upsertPatchItem()` 与独立安装器的 `restoreConfigs()` 都先把这种文档当空处理,否则追加会写出两份 YAML 文档。
16
+ - **重复 id**:同一 id 多条时,`upsertPatchItem()` 改最后一条(loader 生效的那条)并删除前面的重复;`captureConfigs()` 以带 config 的那条为准,并在结果说明里留一行提示。
17
+ - **打包速度与代码组织**:zip 跳过已压缩扩展名(`alreadyCompressed`),小文件 9 级、大于 64 KB 用 6 级;扫描对同内容文件按 sha1 复用结论;HTTP 样板移到 `lib/http.mjs`(`sendJson` / `readBody` / `readRawBody` / `asJson`),`index.js` 的 `VERSION` 改为读 `package.json`。
11
18
  - **可选项**:是否带插件本体、是否带配置与数据快照、打包前是否扫描。
12
19
  - **检测(打包前强制)**:打包一定会扫,没有关掉的路径——开关照常显示但点不动,点一下弹红字「你想干什么」五秒;API 里写 `scanBeforePack: false` 也会被拉回 `true`。安装前再扫一次(这一项可以关,默认开)。规则覆盖私钥、云厂商与代码托管 token、常见大模型 key、Cookie/会话字段、邮箱与手机号、内网地址、本机用户路径,以及 `curl|sh`、`powershell -enc`、`eval`/`new Function`、可疑长 base64、关闭证书校验、`postinstall` 脚本等。
13
20
  - **兼容性**:与已装版本、peer 依赖、`engines.dsh`/`engines.node`、许可证允许列表比对,给出等级、原因与建议;有阻断项时默认不装。
@@ -20,12 +27,12 @@
20
27
  - **进度窗的收尾**:失败与取消的记录只留十几秒,完成的按设置 `jobKeepSeconds`(默认 60 秒,0 = 收尾即清)清掉,卡住的 running(十分钟没有新进度)先判失败再收走;只有正在跑的、停在风险点的会一直留着。「清空进程」是乐观更新(先在界面摘掉再通知服务端),单条「删除该进程」同样会收掉安装页那条结论。
21
28
  - **与插件市场联动(建议先装市场,但非必须)**:目录直接读市场自己的目录包 `dsh-plugin-catalog`(CDN 的 `index.json` 优先,取不到退回 npm tarball),分区名与条目数跟市场一致;本机列表来自同一个 `node_modules`;安装走同一条 `dsh plugin add` 链路,所以两边装的插件互相可见。已装插件会从目录补齐描述与分区,并标出「市场新版 x.y.z」。
22
29
  - **装了市场**:目录、分类、搜索、「切换市场版」、市场版版本对比都在;市场的 Discover 栏与本插件的「插件页内」栏并排,互不占位。
23
- - **没装市场**:打包、装包、强制检测、完整性/兼容/许可证校验、配置回填、装好先不启用、三处入口**全部照常**(这些槽位由 DSH 核心声明,不依赖市场插件)。少的只有市场 Discover 界面,以及**尚未建过目录索引时**的分类胶囊、搜索、市场版对比与「切换市场版」。建一次索引(5~30 秒)即恢复。
30
+ - **没装市场**:打包、装包(有市场版时默认取上游原版的判断需要一次目录索引)、强制检测、完整性/兼容/许可证校验、配置回填、装好先不启用、三处入口**全部照常**(这些槽位由 DSH 核心声明,不依赖市场插件)。少的只有市场 Discover 界面,以及**尚未建过目录索引时**的分类胶囊、搜索、市场版对比与「切换市场版」。建一次索引(5~30 秒)即恢复。
24
31
  - **没索引又没网**:首屏仍只列已装插件;已装行的分类退回内置兜底规则,与 23 类的 id 不完全对得上,按 theme / memory 之类筛会漏几条;轻量包装不了(需按清单版本联网取包),完整版照装。
25
32
  - **分类 + 搜索 + 分页**:分类就是市场的 23 个分区。首屏只列本机已装的插件,不联网;输入关键词或点分类才去目录里搜,服务端分页(默认每页 20 条,可改),底部「加载更多」。排序照抄市场:已装优先 → 相关度(整字段 > 包含 > 其它词,包名权重最高)→ 目录原序;本机独有、目录里没有的插件也能搜到。
26
33
  - **风险确认**:检出高危时不再直接拒绝,而是把任务停在 `paused` 等待确认「我知道在干什么」;确认状态写进清单 `security.acknowledged`,报告照常列出命中。市场收录与否只影响 `security.trustedOnly` 与提示措辞。
27
34
  - **快捷选择**:打包页搜索框右侧有「全部加入」(本机已装全部插件,按「基础配置」)与「清除选择」。
28
- - **切换市场版**:本机已装插件若在目录里有同名条目,行末有小字「(切换市场版)」——改用上游原版代码 + 默认配置打包;再点「(切回本机版)」回到本机快照。同名可能是撞名,所以只作为选项,默认仍打本机那份。
35
+ - **默认按市场版打包**:本机已装插件若在目录里有同名条目,勾选时默认走市场版本(`source: "npm"`、`spec` 取市场版本号),安装时不会装成本地开发版;行末「(切回本机版)」可改回本机快照,那时才出现「基础配置 / 本地改动」。同名未必是同一个插件,判断依据是目录里的同名条目,最终以打包页显示的来源为准。
29
36
  - **显示位置**:设置页底部三个独立开关(设置页内 / 侧边栏 / 插件页内),改了立刻挂上或撤下,不用重启;只剩一处时那个开关会变灰、点不动,接口层也会拒绝三处全关,免得再没有入口关回来。
30
37
  - **装完是否启用**:安装页与设置里都有「安装后直接启用」,默认关。关的时候文件与依赖照装,但装完会把 `dsh.profile.bundles` 精确撤回原样——重启也不加载,想用再手动登记或重装时勾上。
31
38
 
@@ -86,6 +93,8 @@ data/<目录名>/** 插件数据快照(仅小体积文本;目录名取
86
93
  - `POST /packs { dir }`:列任意目录(绝对路径)里的 `.dshpack`,条目带绝对 `path`;`GET /packs` 仍读插件自己的 `packs`。`inspectInput` 支持绝对路径的 `file`,所以选中即按路径读。
87
94
  - 进程清理:`/jobs/clear` 只留 `running` 与 `paused`,其余(含 4% 就因许可证被拒的失败任务、卡住的假 running)都清掉;客户端「清空进程」在有任务时常驻,批量失败会退回逐条 `/jobs/dismiss`。`pruneJobs()` 由设置 `jobKeepSeconds`(默认 60 秒,0 = 收尾即清)驱动:完成/已确认的按它清,失败/取消的取 `min(它, 15 秒)`,仍在 `running` 但心跳(`updatedAt`)超过 10 分钟的先被判成失败再一起清;`paused`(等风险决定)永不自动清。安装任务在结果写进页面后由客户端自动 `/jobs/dismiss`。客户端的「清空进程」是乐观更新:先把收尾的行从界面摘掉并 `fireClear()`,再 `POST /jobs/clear`,失败时退回逐条 `/jobs/dismiss`。
88
95
 
96
+ - **市场来源固定先走市场**:清单里 `source` 为 `npm`/`market` 的插件,说明包内那份只是市场包的副本,安装时即使关掉 `preferMarket` 也先按 `名字@版本` 从 registry 装,失败才退回包内副本(`assets/install-stub.mjs` 同样先试市场、再退回 `file:` 副本);动作里的 `source` 仍是 `market`。
97
+
89
98
  ## 安装顺序与「已装先跳过」
90
99
 
91
100
  安装与打包共用任务队列(`GET /jobs` 里 `kind: "install"`):`POST /install { async: true }` 立即返回 job,进度由 `installPack` 的 `onProgress` 推进(8 检查已装 → 12~80 逐插件 → 84 登记启用清单 → 92 回填配置 → 100 完成)。
package/index.js CHANGED
@@ -19,51 +19,15 @@ import { catalogSummary, searchCatalog, syncCatalog, categoryMapFor, lookupPlugi
19
19
  import { parseYaml } from './lib/yamlish.mjs'
20
20
  import { readPatch } from './lib/profile.mjs'
21
21
  import { buildReadme, pluginSummary } from './lib/manifest.mjs'
22
+ import { sendJson as json, readBody, readRawBody, asJson, MAX_JSON_BODY, MAX_DROP_BODY } from './lib/http.mjs'
22
23
 
23
- const VERSION = '0.1.0'
24
- const MAX_JSON_BODY = 1024 * 1024
25
- // 直接拖进来的整合包走原始字节(不塞 base64),上限与单次下载一致,够装大包
26
- const MAX_DROP_BODY = 256 * 1024 * 1024
24
+ const VERSION = (() => {
25
+ try { return JSON.parse(fs.readFileSync(new URL('./package.json', import.meta.url), 'utf8')).version || '0.0.0' } catch { return '0.0.0' }
26
+ })()
27
27
  const PENDING_TTL = 30 * 60 * 1000
28
28
  const PENDING_MAX = 4
29
29
  const PENDING_BYTES = 512 * 1024 * 1024
30
30
 
31
- const json = (res, code, obj) => {
32
- res.writeHead(code, { 'Content-Type': 'application/json; charset=utf-8', 'Cache-Control': 'no-store' })
33
- res.end(JSON.stringify(obj))
34
- }
35
-
36
- const readBody = (req, limit = MAX_JSON_BODY) => new Promise((resolve, reject) => {
37
- let size = 0
38
- const chunks = []
39
- req.on('data', (chunk) => {
40
- size += chunk.length
41
- if (size > limit) { reject(Object.assign(new Error('请求体过大'), { statusCode: 413 })); req.destroy(); return }
42
- chunks.push(chunk)
43
- })
44
- req.on('end', () => resolve(Buffer.concat(chunks).toString('utf8')))
45
- req.on('error', reject)
46
- })
47
-
48
- const readRawBody = (req, limit = MAX_DROP_BODY) => new Promise((resolve, reject) => {
49
- let size = 0
50
- const chunks = []
51
- req.on('data', (chunk) => {
52
- size += chunk.length
53
- if (size > limit) {
54
- reject(Object.assign(new Error('整合包太大:上限 ' + Math.round(limit / 1024 / 1024) + ' MB'), { statusCode: 413 }))
55
- req.destroy()
56
- return
57
- }
58
- chunks.push(chunk)
59
- })
60
- req.on('end', () => resolve(Buffer.concat(chunks)))
61
- req.on('error', reject)
62
- })
63
-
64
- const asJson = (text, fallback) => {
65
- try { return JSON.parse(text) } catch { return fallback }
66
- }
67
31
 
68
32
  export default {
69
33
  name: 'dsh-modpack-kit',
@@ -112,7 +76,12 @@ export default {
112
76
  pluginsTab: config.showInPluginsTab === true,
113
77
  },
114
78
  installedTotal: installed.length,
115
- installed: installed.filter((p) => p.isPlugin).map((p) => ({
79
+ // 插件自带的内部子包(由父包依赖一起装进来)与残留包不单独列;只给数字,界面上说明一句
80
+ installedHidden: installed.filter((p) => p.isPlugin && !p.isDirect).length,
81
+ installedOrphans: installed.filter((p) => !p.isDirect && p.isOrphan).length,
82
+ // 只列 profile 直接声明的插件;插件自带的内部子包(如壁纸引擎的 fonts/fx/glass…)由父包带进来,
83
+ // 单独列出来会被重复打包、重复安装。
84
+ installed: installed.filter((p) => p.isPlugin && p.isDirect).map((p) => ({
116
85
  name: p.name,
117
86
  version: p.version,
118
87
  description: p.description || '',
@@ -247,7 +216,7 @@ export default {
247
216
  // 首屏只要「已装 + 分类」,不再整份目录下发;搜索走服务端分页,一次一页。
248
217
  route('/dsh-modpack-kit/api/catalog', async (req, res) => {
249
218
  if (req.method !== 'GET') { json(res, 405, { ok: false }); return }
250
- const installedList = installedOrEmpty().filter((p) => p.isPlugin).map((p) => ({
219
+ const installedList = installedOrEmpty().filter((p) => p.isPlugin && p.isDirect).map((p) => ({
251
220
  name: p.name, version: p.version, isBundle: p.isBundle, hasClient: p.hasClient, description: p.description || '',
252
221
  }))
253
222
  let catalog = null
@@ -290,7 +259,7 @@ export default {
290
259
  route('/dsh-modpack-kit/api/catalog/search', async (req, res) => {
291
260
  if (!needPost(req, res)) return
292
261
  const body = asJson(await readBody(req), {}) || {}
293
- const localPlugins = installedOrEmpty().filter((p) => p.isPlugin)
262
+ const localPlugins = installedOrEmpty().filter((p) => p.isPlugin && p.isDirect)
294
263
  const localCategories = categoryMapFor(config, localPlugins.map((p) => p.name))
295
264
  const installed = localPlugins.map((p) => ({
296
265
  name: p.name, version: p.version, description: p.description || '',
@@ -432,7 +401,16 @@ export default {
432
401
  const result = await buildPack({
433
402
  selection: selection.map((item) => {
434
403
  const name = String(item.name || '')
435
- const here = installed.some((p) => p.name === name)
404
+ const entry = installed.find((p) => p.name === name)
405
+ if (entry && entry.isDirect === false) {
406
+ // 插件自带的内部子包(例如壁纸引擎的 fonts/fx/glass…)会随父包一起装,
407
+ // 单独打包会让它被重复安装;既没人声明、也不在依赖树里的残包同理不单独打。
408
+ const why = entry.transitiveOf
409
+ ? '是「' + entry.transitiveOf + '」的内部组件,会随父包一起装上'
410
+ : '不在 profile 的依赖清单里(像是删插件后留下的残包),重新装一次它所属的插件即可'
411
+ throw new Error('「' + name + '」' + why + ',不能单独打包')
412
+ }
413
+ const here = Boolean(entry)
436
414
  // 市场里没装的插件也能打包:本机没有这份代码,就从 registry 按版本取包
437
415
  const source = item.source === 'npm' || item.source === 'market' || !here ? 'npm' : 'profile'
438
416
  return {
package/lib/http.mjs ADDED
@@ -0,0 +1,38 @@
1
+ /**
2
+ * HTTP 小工具:JSON 响应、请求体读取(文本 / 原始字节)。
3
+ *
4
+ * 只被 index.js 的各个路由使用;抽出来是为了让路由文件不再堆着读流的样板代码。
5
+ */
6
+
7
+ export const MAX_JSON_BODY = 1024 * 1024
8
+ // 直接拖进来的整合包走原始字节(不塞 base64),上限与单次下载一致
9
+ export const MAX_DROP_BODY = 256 * 1024 * 1024
10
+
11
+ export function sendJson(res, code, obj) {
12
+ res.writeHead(code, { 'Content-Type': 'application/json; charset=utf-8', 'Cache-Control': 'no-store' })
13
+ res.end(JSON.stringify(obj))
14
+ }
15
+
16
+ const collect = (req, limit, tooBig) => new Promise((resolve, reject) => {
17
+ let size = 0
18
+ const chunks = []
19
+ req.on('data', (chunk) => {
20
+ size += chunk.length
21
+ if (size > limit) {
22
+ reject(Object.assign(new Error(tooBig), { statusCode: 413 }))
23
+ req.destroy()
24
+ return
25
+ }
26
+ chunks.push(chunk)
27
+ })
28
+ req.on('end', () => resolve(Buffer.concat(chunks)))
29
+ req.on('error', reject)
30
+ })
31
+
32
+ export const readBody = (req, limit = MAX_JSON_BODY) => collect(req, limit, '请求体过大').then((buf) => buf.toString('utf8'))
33
+
34
+ export const readRawBody = (req, limit = MAX_DROP_BODY) => collect(req, limit, '整合包太大:上限 ' + Math.round(limit / 1024 / 1024) + ' MB')
35
+
36
+ export function asJson(text, fallback) {
37
+ try { return JSON.parse(text) } catch { return fallback }
38
+ }
package/lib/install.mjs CHANGED
@@ -232,6 +232,12 @@ export async function installPack(input) {
232
232
  actions.push({ plugin: plugin.name, action: 'skipped', ok: true, message: '这次不动它(你只选了替换其中几个)' })
233
233
  continue
234
234
  }
235
+ if (plugin.transitiveOf) {
236
+ // 同一个包里父包会把它带进来,单独装一遍会重复
237
+ actions.push({ plugin: plugin.name, action: 'skipped', ok: true, message: '是「' + plugin.transitiveOf + '」的内部组件,随父包一起安装' })
238
+ lines.push('跳过单独安装:' + plugin.name + ' 是「' + plugin.transitiveOf + '」的内部组件,会随父包一起装上')
239
+ continue
240
+ }
235
241
  const existing = installed.find((p) => p.name === plugin.name)
236
242
  if (existing && deferExisting) {
237
243
  // 同名或同插件不同版本都算已装:先跳过,其余照装,最后让你决定换不换
@@ -246,14 +252,18 @@ export async function installPack(input) {
246
252
  }
247
253
 
248
254
  // 联网且插件市场可用时,优先按市场版本装(用户要求:装整合包时优先同步市场版本)
249
- // 取不到 / 离线 / 关掉开关(options.preferMarket === false)时,按包内带来的那份装
255
+ // 取不到 / 离线 / 关掉开关(options.preferMarket === false)时,按包内带来的那份装。
256
+ // 例外:包里这份当初就是从插件市场取的(source npm/market),无论开关如何都优先走市场,
257
+ // 因为包内那份只是同一份市场包的副本;市场取不到再退回包内副本。
258
+ const fromMarketSource = plugin.source === 'npm' || plugin.source === 'market'
250
259
  let marketHit = null
251
- if (options.preferMarket !== false && typeof context.resolveMarket === 'function') {
260
+ if ((options.preferMarket !== false || fromMarketSource) && typeof context.resolveMarket === 'function') {
252
261
  try {
253
262
  marketHit = await context.resolveMarket(plugin)
254
263
  } catch (error) {
255
264
  lines.push('查不到市场版本(' + plugin.name + '):' + String(error?.message || error) + ',按包内的来')
256
265
  }
266
+ if (!marketHit && fromMarketSource) lines.push('「' + plugin.name + '」是按市场版打包的,但这次没取到市场版本,改用包内自带的副本')
257
267
  }
258
268
 
259
269
  let dir = null
@@ -359,6 +369,32 @@ export async function installPack(input) {
359
369
  actions.push({ plugin: plugin.name, action: 'install', ok: false, message: 'dsh plugin add 失败(退出码 ' + code + '),详见日志' })
360
370
  continue
361
371
  }
372
+ if (marketHit && plugin.localEdits) {
373
+ // 身份与内容都要:依赖写成 名字@版本(插件市场认它是市场版,不是本地开发版),
374
+ // 再把包里带来的本地改动覆盖到装好的那份上——否则本机版的改动就丢了。
375
+ const installName = plugin.dirName || plugin.name
376
+ const prefix = 'plugins/' + installName + '/'
377
+ const payloadEntries = entries.filter((entry) => entry.name.startsWith(prefix))
378
+ if (payloadEntries.length > 0) {
379
+ const installDir = path.join(profileDir, 'node_modules', installName)
380
+ let overlayed = 0
381
+ let failed = 0
382
+ for (const entry of payloadEntries) {
383
+ const rel = entry.name.slice(prefix.length)
384
+ if (!rel) continue
385
+ const target = path.join(installDir, rel)
386
+ try {
387
+ fs.mkdirSync(path.dirname(target), { recursive: true })
388
+ fs.writeFileSync(target, entry.data)
389
+ overlayed += 1
390
+ } catch {
391
+ failed += 1
392
+ }
393
+ }
394
+ lines.push('「' + plugin.name + '」按市场版安装(依赖是 ' + marketHit.spec + ',插件市场认它作市场版),并把包内的本地改动覆盖上去(' + overlayed + ' 个文件' + (failed ? ',' + failed + ' 个写不进去' : '') + ')')
395
+ }
396
+ }
397
+
362
398
  if (plugin.isBundle && plugin.hasPatch) touchedBundles.push(plugin.name)
363
399
  actions.push({
364
400
  plugin: plugin.name,
package/lib/manifest.mjs CHANGED
@@ -43,6 +43,8 @@ function normalizePlugin(raw) {
43
43
  hasClient: bool(raw.hasClient),
44
44
  hasPatch: bool(raw.hasPatch),
45
45
  isBundle: raw.isBundle !== false,
46
+ // 谁的内部组件:装父包时会一起装上,安装侧据此跳过,不重复装
47
+ transitiveOf: typeof raw.transitiveOf === 'string' && /^[@A-Za-z0-9._\/-]{1,160}$/u.test(raw.transitiveOf) ? raw.transitiveOf : '',
46
48
  localEdits: bool(raw.localEdits),
47
49
  // 老包没有 mode 字段,用 localEdits 兜底
48
50
  mode: raw.mode === 'local' ? 'local' : raw.mode === 'base' ? 'base' : bool(raw.localEdits) ? 'local' : 'base',
package/lib/pack.mjs CHANGED
@@ -157,12 +157,21 @@ export function captureConfigs(patchText, plugins, parsePatch) {
157
157
  }
158
158
  if (!Array.isArray(items)) return { captured, notes }
159
159
  const byName = new Map(plugins.map((p) => [p.name, p]))
160
+ const duplicateIds = new Set()
160
161
  for (const item of items) {
161
162
  if (!item || typeof item !== 'object') continue
162
163
  const name = typeof item.name === 'string' ? item.name : ''
163
164
  const id = typeof item.id === 'string' ? item.id : ''
164
165
  const hit = byName.get(name) || byName.get(id)
165
166
  if (!hit) continue
167
+ // 同一个 id 可能有多条(常见的是早先一条带 config、后来又追加一条 disabled 的)。
168
+ // 抓配置要挑有内容的那条,别让后面的空条目把前面的盖掉。
169
+ const seen = captured.get(hit.name)
170
+ const hasConfig = item.config !== null && item.config !== undefined
171
+ if (seen && (!hasConfig || (seen.config !== null && seen.config !== undefined))) {
172
+ duplicateIds.add(item.id || hit.name)
173
+ continue
174
+ }
166
175
  // 配置里最可能藏 token;打包前按字段名与明文特征先抹掉,包离手之后就不会再漏。
167
176
  const redacted = redactConfig(item.config ?? null)
168
177
  if (redacted.paths.length > 0) {
@@ -176,6 +185,9 @@ export function captureConfigs(patchText, plugins, parsePatch) {
176
185
  ...(redacted.paths.length > 0 ? { configRedacted: redacted.paths } : {}),
177
186
  })
178
187
  }
188
+ if (duplicateIds.size > 0) {
189
+ notes.push('补丁层里有重复条目的 id(以带 config 的那条为准):' + [...duplicateIds].slice(0, 6).join(', '))
190
+ }
179
191
  return { captured, notes }
180
192
  }
181
193
 
@@ -293,6 +305,8 @@ export async function buildPack(input) {
293
305
  let payload = []
294
306
  let notes = []
295
307
  let manifestPlugins = []
308
+ // 每个插件自己的依赖名(用来判断「谁是谁的内部组件」)
309
+ const depsOf = new Map()
296
310
  let capturedFiles = []
297
311
  let scan = null
298
312
  let trustedOnly = false
@@ -405,10 +419,29 @@ export async function buildPack(input) {
405
419
  dirName,
406
420
  }
407
421
  manifestPlugins.push(entry)
422
+ depsOf.set(name, {
423
+ ...(pkg.dependencies && typeof pkg.dependencies === 'object' ? pkg.dependencies : {}),
424
+ ...(pkg.optionalDependencies && typeof pkg.optionalDependencies === 'object' ? pkg.optionalDependencies : {}),
425
+ })
408
426
  payload.push(...files.map((f) => ({ ...f, plugin: name })))
409
427
  tick('collect', 6 + 34 * (manifestPlugins.length / Math.max(1, selection.length)), '收集 ' + name + ' 的文件')
410
428
  }
411
429
 
430
+ // 同一个包里若 A 依赖 B,B 就是 A 的内部组件:装 A 时会被一起装上,
431
+ // 清单里标出 transitiveOf,安装侧(插件内与独立安装器)据此跳过 B,避免重复装两遍。
432
+ const namesInPack = new Set(manifestPlugins.map((plugin) => plugin.name))
433
+ for (const plugin of manifestPlugins) {
434
+ if (plugin.transitiveOf) continue
435
+ const deps = depsOf.get(plugin.name) || {}
436
+ for (const dep of Object.keys(deps)) {
437
+ if (dep === plugin.name || !namesInPack.has(dep)) continue
438
+ const target = manifestPlugins.find((candidate) => candidate.name === dep)
439
+ if (!target || target.transitiveOf) continue
440
+ target.transitiveOf = plugin.name
441
+ notes.push('「' + dep + '」是「' + plugin.name + '」的内部组件:装机时随父包一起装,不单独装一遍')
442
+ }
443
+ }
444
+
412
445
  // 配置与数据快照
413
446
  capturedFiles = []
414
447
  if (options.includeConfig) {
package/lib/profile.mjs CHANGED
@@ -60,7 +60,9 @@ export function listInstalled(profileDir) {
60
60
  isPlugin: Boolean(
61
61
  pkg.dsh
62
62
  || (Array.isArray(pkg.keywords) && pkg.keywords.includes('dsh-plugin'))
63
- || /^(?:@[^/]+\/)?dsh[-.]/u.test(name),
63
+ || /^(?:@[^/]+\/)?dsh[-.]/u.test(name)
64
+ // 目录名可能是别名,真正说明身份的是 package.json 的 name
65
+ || /^(?:@[^/]+\/)?dsh[-.]/u.test(typeof pkg.name === 'string' ? pkg.name : ''),
64
66
  ),
65
67
  size,
66
68
  })
@@ -78,7 +80,59 @@ export function listInstalled(profileDir) {
78
80
  }
79
81
  push(dirent.name, '')
80
82
  }
81
- out.sort((a, b) => (a.isBundle === b.isBundle ? a.name.localeCompare(b.name) : a.isBundle ? -1 : 1))
83
+ // 只把「用户自己装进来」的包当成独立插件:一个插件常把内部组件也发成 dsh-plugin-* 子包
84
+ // (例如 dsh-plugin-wallpaper-engine 带 fonts / fx / glass / parallax … 等 8 个),
85
+ // 它们是父包的 dependencies、由父包一起装进来;单独列出来会被重复打包、重复安装。
86
+ // 判定分三步:① profile 里声明的依赖与 bundles 登记的算「直接装」;② 从它们出发按
87
+ // dependencies/optionalDependencies 递归走一遍,凡是走到、但自己没被直接声明的,都是子包,
88
+ // 记下「谁是父包」;③ 既没被声明、也走不到的,是残留包(isOrphan),同样不列成插件。
89
+ const profilePkg = readProfilePackage(profileDir) || {}
90
+ const declared = new Set([
91
+ ...Object.keys(profilePkg.dependencies || {}),
92
+ ...Object.keys(profilePkg.optionalDependencies || {}),
93
+ ])
94
+ let registered = []
95
+ try { registered = readBundles(profilePkg) } catch { registered = [] }
96
+ const direct = new Set([...declared, ...registered])
97
+ // 目录名与 package.json 里的 name 可能不同(scoped、别名、手工改过的包),两边都建索引
98
+ const byKey = new Map()
99
+ for (const item of out) {
100
+ byKey.set(item.dirName, item)
101
+ if (item.name && !byKey.has(item.name)) byKey.set(item.name, item)
102
+ }
103
+ const parentOf = new Map()
104
+ const queue = [...direct].filter((name) => byKey.has(name))
105
+ const seen = new Set(queue)
106
+ while (queue.length > 0) {
107
+ const parentKey = queue.shift()
108
+ const parentItem = byKey.get(parentKey)
109
+ const parentPkg = (parentItem || {}).pkg
110
+ if (!parentPkg || typeof parentPkg !== 'object') continue
111
+ const parentLabel = parentItem.name || parentItem.dirName || parentKey
112
+ const kids = [
113
+ ...Object.keys(parentPkg.dependencies || {}),
114
+ ...Object.keys(parentPkg.optionalDependencies || {}),
115
+ ]
116
+ for (const kid of kids) {
117
+ if (kid === parentLabel || kid === parentKey) continue
118
+ if (!parentOf.has(kid)) parentOf.set(kid, parentLabel)
119
+ if (!seen.has(kid) && byKey.has(kid)) {
120
+ seen.add(kid)
121
+ queue.push(kid)
122
+ }
123
+ }
124
+ }
125
+ for (const item of out) {
126
+ const isDirect = direct.has(item.dirName) || (item.name ? direct.has(item.name) : false)
127
+ const parent = parentOf.get(item.name) || parentOf.get(item.dirName) || ''
128
+ item.isDirect = isDirect
129
+ item.transitiveOf = isDirect ? '' : parent
130
+ // 既不在依赖清单里、也不在任何插件的依赖树里:多是删插件后留下的残包
131
+ item.isOrphan = !isDirect && !parent
132
+ }
133
+ out.sort((a, b) => (a.isBundle === b.isBundle
134
+ ? (a.isDirect === b.isDirect ? a.name.localeCompare(b.name) : a.isDirect ? -1 : 1)
135
+ : a.isBundle ? -1 : 1))
82
136
  return out
83
137
  }
84
138
 
package/lib/yamlish.mjs CHANGED
@@ -366,17 +366,29 @@ export function splitTopLevelItems(text) {
366
366
  * @returns {{text: string, action: 'replaced'|'inserted'}}
367
367
  */
368
368
  export function upsertPatchItem(text, value) {
369
+ // DSH 新建 profile 的补丁文件是「几行注释 + []」。若不先把这段空文档当成空,
370
+ // 追加出来的文件会变成两份 YAML 文档([] 之后再跟 - id: …),整个补丁层解析失败。
371
+ const bare = String(text ?? '').split(/\r?\n/u).map((line) => line.trim()).filter((line) => line !== '' && !line.startsWith('#'))
372
+ if (bare.length === 0 || (bare.length === 1 && /^(?:\[\s*\]|\{\s*\}|null|~)$/u.test(bare[0]))) text = ''
369
373
  const { items, preamble, postamble, lines } = splitTopLevelItems(text)
370
374
  const emitted = emitYaml([{ ...value, config: value.config ?? {} }], 0)
371
- const index = items.findIndex((it) => it.value && it.value.id === value.id)
372
- if (index === -1) {
375
+ const matches = items.map((it, index) => (it.value && it.value.id === value.id ? index : -1)).filter((index) => index >= 0)
376
+ if (matches.length === 0) {
373
377
  const base = String(text ?? '')
374
378
  const trimmed = base.replace(/\s*$/u, '')
375
379
  return { text: (trimmed === '' ? '' : trimmed + '\n') + emitted + '\n', action: 'inserted' }
376
380
  }
377
- const target = items[index]
381
+ // 同一个 id 在补丁层里可能出现多次(例如先写过一条、后来又写了一条 disabled 的)。
382
+ // loader 以最后一条为准,所以改值必须落在最后那条上;前面重复的顺手删掉,免得两份配置打架。
383
+ const targetIndex = matches[matches.length - 1]
384
+ const target = items[targetIndex]
378
385
  const trailingNewline = String(text ?? '').endsWith('\n')
379
- const rebuilt = [...lines.slice(0, target.start), ...emitted.split('\n'), ...lines.slice(target.end)].join('\n')
386
+ let rebuiltLines = [...lines.slice(0, target.start), ...emitted.split('\n'), ...lines.slice(target.end)]
387
+ for (const index of matches.slice(0, -1).reverse()) {
388
+ const it = items[index]
389
+ rebuiltLines = [...rebuiltLines.slice(0, it.start), ...rebuiltLines.slice(it.end)]
390
+ }
391
+ const rebuilt = rebuiltLines.join('\n')
380
392
  const out = trailingNewline && !rebuilt.endsWith('\n') ? rebuilt + '\n' : rebuilt
381
393
  return { text: out, action: 'replaced' }
382
394
  }
package/lib/zip.mjs CHANGED
@@ -101,7 +101,9 @@ export function writeZip(entries, options = {}) {
101
101
  let body = data
102
102
  if (entry.compress !== false && data.length > 128 && !alreadyCompressed(name)) {
103
103
  // 大文件降到 6 级:9 级省下的那点体积不值那几倍 CPU,包越大差得越明显。
104
- const level = data.length > 2 * 1024 * 1024 ? 6 : 9
104
+ // 小文件用 9 级(体积收益明显、CPU 便宜),大文件降到 6 级:
105
+ // 9 级相对 6 级通常只省几个百分点体积,却要多花一倍以上的时间。
106
+ const level = data.length > 64 * 1024 ? 6 : 9
105
107
  const deflated = deflateRawSync(data, { level })
106
108
  if (deflated.length < data.length) {
107
109
  method = 8
package/locale/en.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "meta": {
3
3
  "title": "Modpack",
4
- "description": "Provides HMCL/PCL-style modpack packaging and installation for DeepSeek Harness: bundle several plugins with their configuration and data into one .dshpack and install it in a single pass. Two forms: a self-contained full pack that a machine with only DSH installed can install, and a lite pack that records names and versions and fetches them on install. Each plugin can be packed from its upstream release with default configuration or from a local copy (code, config entries, data snapshot); configuration is re-applied by entry, data is restored under ~/.dsh without overwriting existing files, and suspected credentials become ${REDACTED}. Categories, search, paging and entries come from the plugin-market catalog, and market versions are preferred when online. Packing always runs an in-memory scan for secrets and risky code (masked, never written to disk); high-risk hits pause the job until confirmed, then it resumes from the checkpoint without rescanning. Installation re-checks sha256 integrity, compatibility and licences, and can finish without enabling or enable right away. The UI can live in settings, the sidebar or the plugins tab, each switchable. Installing the plugin market (dshmarket) first is recommended, not required.",
4
+ "description": "Provides HMCL/PCL-launcher-style modpack packaging and installation for DeepSeek Harness: bundle several plugins with their configuration and data into one .dshpack and install it in a single pass. Two forms: a self-contained full pack that a machine with only DSH installed can install, and a lite pack that records names and versions and fetches them on install. Each plugin can be packed from its upstream release with default configuration or from a local copy (code, config entries, data snapshot); configuration is re-applied by entry, data is restored under ~/.dsh without overwriting existing files, and suspected credentials become ${REDACTED}. Categories, search, paging and entries come from the plugin-market catalog, and market versions are preferred when online. Packing always runs an in-memory scan for secrets and risky code (masked, never written to disk); high-risk hits pause the job until confirmed, then it resumes from the checkpoint without rescanning. Installation re-checks sha256 integrity, compatibility and licences, and can finish without enabling or enable right away. The UI can live in settings, the sidebar or the plugins tab, each switchable. Installing the plugin market (dshmarket) first is recommended, not required.",
5
5
  "detail": "docs/DETAIL.md"
6
6
  }
7
7
  }
package/locale/zh.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "meta": {
3
3
  "title": "整合包",
4
- "description": "为 DeepSeek Harness 提供类似 HMCL / PCL 的整合包打包与安装:把多个插件连同各自的配置与数据打成一个 .dshpack 一次装好。支持懒人包(完整包,自带插件本体,目标机器只装 DSH 本体即可安装)与轻量包(只记录插件名与版本,安装时按记录取包);支持按插件逐个定制打包内容(基础配置或本地改动),配置按原结构回填、数据写回 ~/.dsh 且默认不覆盖已有文件,疑似凭据替换为 ${REDACTED};分类、搜索、分页与条目与插件市场目录同源,联网时可优先按市场版本安装。打包前强制做敏感信息与风险代码静态检测(命中只留掩码、原文不落盘),高风险停在「等决定」,确认后从检测点续跑、不重复扫描;安装前校验 sha256 完整性、兼容性与许可证,装完可选先不启用或直接启用;设置页、侧边栏、插件页三处入口各自独立开关。建议先安装插件市场(dshmarket),但不是必须。",
4
+ "description": "为 DeepSeek Harness 提供类似 HMCL / PCL 这类我的世界启动器的整合包打包与安装:把多个插件连同各自的配置与数据打成一个 .dshpack 一次装好。支持懒人包(完整包,自带插件本体,目标机器只装 DSH 本体即可安装)与轻量包(只记录插件名与版本,安装时按记录取包);支持按插件逐个定制打包内容(基础配置或本地改动),配置按原结构回填、数据写回 ~/.dsh 且默认不覆盖已有文件,疑似凭据替换为 ${REDACTED};分类、搜索、分页与条目与插件市场目录同源,联网时可优先按市场版本安装。打包前强制做敏感信息与风险代码静态检测(命中只留掩码、原文不落盘),高风险停在「等决定」,确认后从检测点续跑、不重复扫描;安装前校验 sha256 完整性、兼容性与许可证,装完可选先不启用或直接启用;设置页、侧边栏、插件页三处入口各自独立开关。建议先安装插件市场(dshmarket),但不是必须。",
5
5
  "detail": "docs/DETAIL.md"
6
6
  }
7
7
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "dsh-modpack-kit",
3
- "version": "0.1.5",
4
- "description": "Provides HMCL/PCL-style modpack packaging and installation for DeepSeek Harness: bundle several plugins with their configuration and data into one .dshpack and install it in a single pass. Two forms: a self-contained full pack that a machine with only DSH installed can install, and a lite pack that records names and versions and fetches them on install. Each plugin can be packed from its upstream release with default configuration or from a local copy (code, config entries, data snapshot); configuration is re-applied by entry, data is restored under ~/.dsh without overwriting existing files, and suspected credentials become ${REDACTED}. Categories, search, paging and entries come from the plugin-market catalog, and market versions are preferred when online. Packing always runs an in-memory scan for secrets and risky code (masked, never written to disk); high-risk hits pause the job until confirmed, then it resumes from the checkpoint without rescanning. Installation re-checks sha256 integrity, compatibility and licences, and can finish without enabling or enable right away. The UI can live in settings, the sidebar or the plugins tab, each switchable. Installing the plugin market (dshmarket) first is recommended, not required.",
3
+ "version": "0.1.7-1",
4
+ "description": "Provides HMCL/PCL-launcher-style modpack packaging and installation for DeepSeek Harness: bundle several plugins with their configuration and data into one .dshpack and install it in a single pass. Two forms: a self-contained full pack that a machine with only DSH installed can install, and a lite pack that records names and versions and fetches them on install. Each plugin can be packed from its upstream release with default configuration or from a local copy (code, config entries, data snapshot); configuration is re-applied by entry, data is restored under ~/.dsh without overwriting existing files, and suspected credentials become ${REDACTED}. Categories, search, paging and entries come from the plugin-market catalog, and market versions are preferred when online. Packing always runs an in-memory scan for secrets and risky code (masked, never written to disk); high-risk hits pause the job until confirmed, then it resumes from the checkpoint without rescanning. Installation re-checks sha256 integrity, compatibility and licences, and can finish without enabling or enable right away. The UI can live in settings, the sidebar or the plugins tab, each switchable. Installing the plugin market (dshmarket) first is recommended, not required.",
5
5
  "type": "module",
6
6
  "main": "index.js",
7
7
  "exports": {