dsh-modpack-kit 0.1.9 → 0.2.0-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/lib/install.mjs CHANGED
@@ -258,6 +258,18 @@ export async function installPack(input) {
258
258
  const total = manifest.plugins.length
259
259
  let restartFromManager = false
260
260
 
261
+ // 离线也能装懒人包:完整包(以及混合包里带本体的那几个)代码就在包里。
262
+ // 先快速探一下 registry,不通就别再「先按市场版本装」——不然每个插件都要等一遍超时。
263
+ let offline = options.offline === true
264
+ if (!offline && options.offline !== false && typeof context.probeRegistry === 'function') {
265
+ try {
266
+ offline = !(await context.probeRegistry())
267
+ } catch {
268
+ offline = false
269
+ }
270
+ if (offline) lines.push('现在连不上 registry:本次直接用包里自带的插件(插件市场会显示成本地安装),不联网也能装完')
271
+ }
272
+
261
273
  for (const plugin of manifest.plugins) {
262
274
  const index = manifest.plugins.indexOf(plugin)
263
275
  progress({ pct: 12 + Math.round(((index + 1) / total) * 68), note: '安装 ' + plugin.name + (plugin.version ? ' ' + plugin.version : '') })
@@ -288,7 +300,7 @@ export async function installPack(input) {
288
300
  // 取不到 / 离线 / 关掉开关(options.preferMarket === false)时,按包内带来的那份装。
289
301
  // 例外:包里这份当初就是从插件市场取的(source npm/market),无论开关如何都优先走市场,
290
302
  // 因为包内那份只是同一份市场包的副本;市场取不到再退回包内副本。
291
- const fromMarketSource = plugin.source === 'npm' || plugin.source === 'market'
303
+ const fromMarketSource = !offline && (plugin.source === 'npm' || plugin.source === 'market')
292
304
  let marketHit = null
293
305
  // 包里这份本来就是从 registry 取的(source npm/market)时,版本号已经记在清单里,
294
306
  // 不必再问一次 registry:直接按 name@version 装,插件市场才会把它记成市场版
@@ -296,7 +308,7 @@ export async function installPack(input) {
296
308
  if (fromMarketSource && plugin.version && String(plugin.version) !== '0.0.0' && /^[0-9][0-9A-Za-z.+-]*$/u.test(String(plugin.version))) {
297
309
  marketHit = { spec: plugin.name + '@' + plugin.version, version: String(plugin.version), fromPack: true }
298
310
  }
299
- if (!marketHit && (options.preferMarket !== false || fromMarketSource) && typeof context.resolveMarket === 'function') {
311
+ if (!offline && !marketHit && (options.preferMarket !== false || fromMarketSource) && typeof context.resolveMarket === 'function') {
300
312
  try {
301
313
  marketHit = await context.resolveMarket(plugin)
302
314
  } catch (error) {
@@ -306,17 +318,52 @@ export async function installPack(input) {
306
318
  }
307
319
 
308
320
  let dir = null
321
+ // 这个插件的代码是不是就装在包里(完整包全部是;混合包只有「没有确定版本 / 要带本机改动」的那几个是)
322
+ let embedded = false
309
323
  // 轻量包的代码是刚从 registry 取回来的,装的时候直接用 name@version:
310
324
  // 用 file: 指向临时目录的话,临时目录一删就断,插件市场也会当成「本地安装」。
311
325
  let resolvedSpec = null
326
+ // 轻量包在内存里扫:把 tarball 解出来的条目直接交给扫描器,
327
+ // 不再先落一份到临时目录再扫(少一次磁盘写、也不会有残留要清)。
328
+ let memoryEntries = null
312
329
  if (!marketHit) {
313
- if (manifest.format === 'full' && pluginPayload(entries, plugin.dirName || plugin.name).length > 0) {
330
+ if (pluginPayload(entries, plugin.dirName || plugin.name).length > 0) {
314
331
  try {
315
332
  dir = materializePayload(entries, manifest, plugin, config)
333
+ embedded = true
316
334
  } catch (error) {
317
335
  actions.push({ plugin: plugin.name, action: 'install', ok: false, message: String(error?.message || error) })
318
336
  continue
319
337
  }
338
+ } else if (typeof context.resolveSourceEntries === 'function') {
339
+ if (offline) {
340
+ actions.push({ plugin: plugin.name, action: 'install', ok: false, message: '当前没网:这个包只记版本、没带本体,装不了;联网后再试,或改用完整包(混合包里带本体的插件也一样能离线装)' })
341
+ continue
342
+ }
343
+ try {
344
+ memoryEntries = await context.resolveSourceEntries(plugin)
345
+ if (!Array.isArray(memoryEntries) || memoryEntries.length === 0) throw new Error('取回来的包里没有文件')
346
+ } catch (error) {
347
+ actions.push({ plugin: plugin.name, action: 'install', ok: false, message: '取包失败:' + String(error?.message || error) })
348
+ continue
349
+ }
350
+ if (plugin.version && String(plugin.version) !== '0.0.0') resolvedSpec = plugin.name + '@' + plugin.version
351
+ // 轻量包本体不夹带源码,真正的代码是刚取回来的:装之前必须补扫一遍,否则「安装前检测」是空转
352
+ try {
353
+ const deep = scanEntries(memoryEntries, { extraRules: Array.isArray(config.extraScanRules) ? config.extraScanRules : [] })
354
+ if (deep.counts.high > 0 && !options.force && !acknowledged) {
355
+ actions.push({ plugin: plugin.name, action: 'install', ok: false, message: '从市场取回的代码里有 ' + deep.counts.high + ' 个高风险项,已拦下' })
356
+ continue
357
+ }
358
+ lines.push('轻量包:已补扫从市场取回的 ' + deep.scannedFiles + ' 个文件(高 ' + deep.counts.high + ',全程在内存里,没有落盘)')
359
+ } catch (error) {
360
+ actions.push({ plugin: plugin.name, action: 'install', ok: false, message: '补充扫描失败:' + String(error?.message || error) })
361
+ continue
362
+ }
363
+ if (options.dryRun) {
364
+ actions.push({ plugin: plugin.name, action: 'install', ok: true, message: '演练:将按 ' + (resolvedSpec || plugin.name) + ' 从市场安装(已内存扫描 ' + memoryEntries.length + ' 个文件)' })
365
+ continue
366
+ }
320
367
  } else if (typeof context.resolveSource === 'function') {
321
368
  try {
322
369
  dir = await context.resolveSource(plugin, packRoot)
@@ -329,8 +376,8 @@ export async function installPack(input) {
329
376
  continue
330
377
  }
331
378
 
332
- if (manifest.format !== 'full') {
333
- if (plugin.version && String(plugin.version) !== '0.0.0') resolvedSpec = plugin.name + '@' + plugin.version
379
+ if (!embedded) {
380
+ if (!resolvedSpec && plugin.version && String(plugin.version) !== '0.0.0') resolvedSpec = plugin.name + '@' + plugin.version
334
381
  // 轻量包本体不夹带源码,真正的代码是刚下载回来的:装之前必须补扫一遍,否则「安装前检测」是空转
335
382
  try {
336
383
  const brought = collectFiles(dir, {
@@ -359,7 +406,13 @@ export async function installPack(input) {
359
406
  continue
360
407
  }
361
408
 
362
- const targetSpec = marketHit ? marketHit.spec : resolvedSpec || 'file:' + dir
409
+ // 完整包默认先按「名字@版本」从市场装:能联网且版本存在时,profile 依赖会写成 ^版本,
410
+ // 插件市场据此认成「市场版」(方案 A)。失败或离线才退回包内副本(file:,市场显示本地安装)。
411
+ let preferMarketSpec = null
412
+ if (!offline && !marketHit && embedded && options.preferMarketOnInstall !== false && options.preferMarket !== false && dir && plugin.version && String(plugin.version) !== '0.0.0' && /^[0-9][0-9A-Za-z.+-]*$/u.test(String(plugin.version))) {
413
+ preferMarketSpec = plugin.name + '@' + String(plugin.version)
414
+ }
415
+ const targetSpec = marketHit ? marketHit.spec : preferMarketSpec || resolvedSpec || 'file:' + dir
363
416
  let attempt = await installSpec(targetSpec, marketHit && marketHit.version ? { name: plugin.name, version: marketHit.version } : null)
364
417
  let code = attempt.code
365
418
  let application = attempt.application
@@ -370,7 +423,7 @@ export async function installPack(input) {
370
423
 
371
424
  // registry 这条路断了时,退回包里/本地已有的那份——能装上比装不上强,但依赖会写成 file:,
372
425
  // 插件市场会把它当成本地安装,所以下面要明确提示。
373
- if (code !== 0 && marketHit && marketHit.fromPack && manifest.format === 'full' && !dir && pluginPayload(entries, plugin.dirName || plugin.name).length > 0) {
426
+ if (code !== 0 && marketHit && marketHit.fromPack && !dir && pluginPayload(entries, plugin.dirName || plugin.name).length > 0) {
374
427
  try {
375
428
  dir = materializePayload(entries, manifest, plugin, config)
376
429
  } catch (error) {
@@ -387,6 +440,16 @@ export async function installPack(input) {
387
440
  if (application === 'restart-required') restartFromManager = true
388
441
  }
389
442
  }
443
+ if (code !== 0 && preferMarketSpec && dir) {
444
+ appendLog('install ' + plugin.name + ' market failed exit=' + code + ' retry=pack')
445
+ lines.push('按 ' + preferMarketSpec + ' 没装成(退出码 ' + code + '),改用包内自带的那份继续(插件市场会显示成本地安装)')
446
+ attempt = await installSpec('file:' + dir, null)
447
+ code = attempt.code
448
+ usedManager = attempt.manager
449
+ application = attempt.application
450
+ if (application === 'restart-required') restartFromManager = true
451
+ preferMarketSpec = null
452
+ }
390
453
  if (code !== 0 && resolvedSpec && dir) {
391
454
  appendLog('install ' + plugin.name + ' market failed exit=' + code + ' retry=file')
392
455
  lines.push('按 ' + resolvedSpec + ' 装失败(退出码 ' + code + '),改用本地已下载的副本重试')
@@ -465,8 +528,16 @@ export async function installPack(input) {
465
528
  let text = patch
466
529
  for (const plugin of manifest.plugins) {
467
530
  const snap = manifest.plugins.find((p) => p.name === plugin.name && p.configIncluded)
531
+ const perPlugin = options.configChoice && typeof options.configChoice === 'object' ? options.configChoice[plugin.name] : undefined
532
+ if (perPlugin === 'local') {
533
+ actions.push({ plugin: plugin.name, action: 'config', ok: true, message: '按你的选择:这个插件保持本机配置,不覆盖' })
534
+ continue
535
+ }
536
+ if (perPlugin === 'pack') {
537
+ // 明确要求用包内配置:跳过「保留本地」的判断
538
+ }
468
539
  if (!snap) continue
469
- if (options.keepLocal !== false && config.keepLocal !== false) {
540
+ if (perPlugin !== 'pack' && options.keepLocal !== false && config.keepLocal !== false) {
470
541
  const captured = captureConfigs(text, [snap], (t) => parseYaml(t)).captured
471
542
  if (captured.size > 0) {
472
543
  actions.push({ plugin: plugin.name, action: 'config', ok: true, message: '本地已有配置,按“保留本地”不覆盖' })
@@ -552,7 +623,7 @@ export async function installPack(input) {
552
623
  if (!groupAdds.has(plugin.group)) groupAdds.set(plugin.group, [])
553
624
  groupAdds.get(plugin.group).push(plugin.name)
554
625
  }
555
- if (groupAdds.size > 0) {
626
+ if (groupAdds.size > 0 && options.syncGroups !== false) {
556
627
  const entriesText = [...groupAdds].map(([name, members]) => name + '(' + members.length + ' 个)').join('、')
557
628
  if (!hasMarket(profileDir)) {
558
629
  lines.push('这个包按分组打包(' + entriesText + '),但目标 profile 没装插件市场,分组没有写入')
package/lib/manifest.mjs CHANGED
@@ -48,6 +48,8 @@ function normalizePlugin(raw) {
48
48
  // 打包时按市场分组整体加入的组名(目标机器有插件市场时并进去)
49
49
  group: typeof raw.group === 'string' && /^[\p{L}\p{N}_ -]{1,40}$/u.test(raw.group) ? raw.group : '',
50
50
  localEdits: bool(raw.localEdits),
51
+ // 混合包里这个插件的本体是不是连代码一起打进包了(false = 安装时按版本取)
52
+ embedded: bool(raw.embedded),
51
53
  configMode: raw.configMode === 'preset' ? 'preset' : raw.configMode === 'custom' ? 'custom' : (bool(raw.localEdits) || bool(raw.configIncluded) ? 'custom' : 'preset'),
52
54
  // 老包没有 mode 字段,用 localEdits 兜底
53
55
  mode: raw.mode === 'local' ? 'local' : raw.mode === 'base' ? 'base' : bool(raw.localEdits) ? 'local' : 'base',
@@ -93,7 +95,7 @@ export function normalizeManifest(raw) {
93
95
  if (seen.has(p.name)) throw new Error('重复插件:' + p.name)
94
96
  seen.add(p.name)
95
97
  }
96
- const format = raw.format === 'full' ? 'full' : 'lite'
98
+ const format = raw.format === 'full' ? 'full' : raw.format === 'hybrid' ? 'hybrid' : 'lite'
97
99
  return {
98
100
  schema: SCHEMA,
99
101
  kind: KIND,
@@ -112,6 +114,7 @@ export function normalizeManifest(raw) {
112
114
  dshVersion: str(raw.dshVersion, 40),
113
115
  options: {
114
116
  includePayload: format === 'full',
117
+ strategy: format,
115
118
  includeConfig: raw.options ? bool(raw.options.includeConfig) : true,
116
119
  includeLocalEdits: raw.options ? bool(raw.options.includeLocalEdits) : false,
117
120
  keepLocalOnInstall: raw.options ? raw.options.keepLocalOnInstall !== false : true,
@@ -149,14 +152,19 @@ export function buildReadme(manifest, extra = {}) {
149
152
  for (const line of manifest.description.split(/\r?\n/u)) lines.push(line)
150
153
  }
151
154
  lines.push('')
152
- lines.push('格式:' + manifest.format + '(' + (manifest.format === 'full' ? '完整版:包含插件本体,任何工具解压即可读' : '轻量版:只有清单,需要 dsh-modpack 插件联网安装') + ')')
155
+ const formatText = manifest.format === 'full'
156
+ ? '完整包:包含插件本体,不联网也能装(有网时优先按市场版本装,装完照样是市场版)'
157
+ : manifest.format === 'hybrid'
158
+ ? '混合包:能按版本装的插件只记版本(安装时联网取包),没有确定版本或带本机改动的插件连本体一起打进来(这部分不用联网);配置/数据快照照常保留'
159
+ : '仅下载码:只有清单与版本号,安装时联网按版本取包,不带配置'
160
+ lines.push('格式:' + manifest.format + '(' + formatText + ')')
153
161
  lines.push('生成:' + manifest.createdAt + ' 生成器:' + manifest.generator.name + ' ' + manifest.generator.version)
154
162
  if (manifest.author) lines.push('打包者:' + manifest.author)
155
163
  if (manifest.dshVersion) lines.push('打包时 DSH 版本:' + manifest.dshVersion)
156
164
  lines.push('')
157
165
  lines.push('包含的插件(' + manifest.plugins.length + ' 个)')
158
166
  for (const p of manifest.plugins) {
159
- lines.push(' · ' + p.name + '@' + p.version + (p.license ? ' [' + p.license + ']' : ' [未标注 license]') + (p.localEdits ? ' (含打包者的本地修改)' : ''))
167
+ lines.push(' · ' + p.name + '@' + p.version + (p.license ? ' [' + p.license + ']' : ' [未标注 license]') + (p.localEdits ? ' (含打包者的本地修改)' : '') + (manifest.format === 'hybrid' ? (p.embedded ? ' (本体在包里)' : ' (安装时按版本从市场取)') : ''))
160
168
  }
161
169
  lines.push('')
162
170
  lines.push('安全检测')
@@ -165,7 +173,10 @@ export function buildReadme(manifest, extra = {}) {
165
173
  lines.push(' 提醒:静态检测不是杀毒,未命中不代表保证安全;安装前请自行确认来源。')
166
174
  lines.push('')
167
175
  lines.push('怎么装')
168
- if (manifest.format === 'lite') {
176
+ if (manifest.format !== 'full') {
177
+ if (manifest.format === 'hybrid') {
178
+ lines.push(' 带本体的插件直接从包里装(不联网也能装);只记版本的插件会联网按版本取包。')
179
+ }
169
180
  lines.push(' 方式 A(有 dsh-modpack 插件):侧栏「整合包 → 安装」选择本文件,会联网按版本取包并校验完整性。')
170
181
  lines.push(' 方式 B(裸 DSH 也能装):解压后运行 install/ 里的安装器,它会按清单里的名字与版本从 registry 取包:')
171
182
  lines.push(' Windows: install\\install.cmd 其它: sh install/install.sh')
package/lib/net.mjs CHANGED
@@ -66,6 +66,8 @@ function curlOnce(url, { timeoutMs, maxBytes, accept }) {
66
66
  const args = ['-sS', '-i', '--max-time', String(Math.max(1, Math.round(timeoutMs / 1000)))]
67
67
  if (maxBytes > 0) args.push('--max-filesize', String(maxBytes))
68
68
  if (process.platform === 'win32') args.push('--ssl-no-revoke')
69
+ // 传输压缩:npm 的版本清单动辄十几 MB,不压缩会让慢链路直接超时
70
+ args.push('--compressed')
69
71
  args.push('-H', 'user-agent: dsh-modpack', '-H', 'accept: ' + (accept || '*/*'), url)
70
72
  execFile('curl', args, { maxBuffer: Math.max(4 * 1024 * 1024, Math.min(maxBytes + 1024 * 1024, 512 * 1024 * 1024)), windowsHide: true }, (error, stdout, stderr) => {
71
73
  if (error) {
@@ -82,7 +84,7 @@ async function fetchOnce(url, { timeoutMs, maxBytes, accept }) {
82
84
  const res = await fetch(url, {
83
85
  redirect: 'manual',
84
86
  signal: AbortSignal.timeout(timeoutMs),
85
- headers: { 'user-agent': 'dsh-modpack', accept: accept || '*/*' },
87
+ headers: { 'user-agent': 'dsh-modpack', accept: accept || '*/*', 'accept-encoding': 'gzip, deflate, br' },
86
88
  })
87
89
  const headers = new Map()
88
90
  for (const [key, value] of res.headers) headers.set(key.toLowerCase(), value)
@@ -155,7 +157,7 @@ export async function requestBuffer(url, config, options = {}) {
155
157
 
156
158
  /** 取 JSON,体积默认 16 MB。 */
157
159
  export async function requestJson(url, config, options = {}) {
158
- const buf = await requestBuffer(url, config, { ...options, maxBytes: options.maxBytes ?? 16 * 1024 * 1024, accept: 'application/json' })
160
+ const buf = await requestBuffer(url, config, { ...options, maxBytes: options.maxBytes ?? 16 * 1024 * 1024, accept: options.accept ?? 'application/json' })
159
161
  try {
160
162
  return JSON.parse(buf.toString('utf8'))
161
163
  } catch {
package/lib/pack.mjs CHANGED
@@ -1,9 +1,10 @@
1
1
  /**
2
2
  * dsh-modpack —— 打包。
3
3
  *
4
- * 两个版本:
5
- * full 完整版:插件本体一起装进 zip,没装 dsh-modpack 的人解压也能按 README 手工装;
6
- * lite 轻量版:只有清单和来源,必须由 dsh-modpack 联网按版本取包。
4
+ * 三种打包策略:
5
+ * full 完整包:插件本体装进 zip,不联网也能装;允许带自定义配置与数据。
6
+ * lite 仅下载码:只有清单与版本号,体积最小;不带配置,装完依赖写成 ^版本(市场认市场版)。
7
+ * hybrid 混合包:只带版本号与配置/数据/补丁片段,不带插件本体;体积接近 lite,配置照样能带。
7
8
  *
8
9
  * 打包顺序是刻意的:先收集 → 先扫描 → 再决定是否允许写盘。扫描在内存里做,
9
10
  * 命中原文不落盘;高风险默认拒绝出包,除非调用方显式 force 并写进报告。
@@ -15,6 +16,7 @@ import { scanEntries, renderScanReport, groupFindings } from './scan.mjs'
15
16
  import { MANIFEST_NAME, SCHEMA, KIND, normalizeManifest, buildReadme, sha256, shortHash } from './manifest.mjs'
16
17
  import { scanFileName } from './scan.mjs'
17
18
  import { slugify } from './store.mjs'
19
+ import { npmMetadata } from './registry.mjs'
18
20
 
19
21
  const STUB_DIR = new URL('../assets/', import.meta.url)
20
22
  const stub = (name) => fs.readFileSync(new URL(name, STUB_DIR))
@@ -311,7 +313,10 @@ export async function buildPack(input) {
311
313
  let scan = null
312
314
  let trustedOnly = false
313
315
  const scanRules = context.extraScanRules || []
314
- const format = options.includePayload === false ? 'lite' : 'full'
316
+ const strategy = options.strategy === 'lite' || options.strategy === 'hybrid'
317
+ ? options.strategy
318
+ : options.includePayload === false ? 'lite' : 'full'
319
+ const format = strategy
315
320
  const progress = typeof options.onProgress === 'function' ? options.onProgress : () => {}
316
321
  const tick = (stage, pct, note) => { try { progress({ stage, pct: Math.max(0, Math.min(100, Math.round(pct))), note }) } catch {} }
317
322
 
@@ -353,16 +358,37 @@ export async function buildPack(input) {
353
358
  ? true
354
359
  : options.includeConfig !== false
355
360
 
361
+ // 混合包按插件分档:能按「名字@版本」装的就只记版本(轻量那部分),
362
+ // 没有确定版本、或要带走本机改动的插件才连代码一起打进包里(完整那部分)。
363
+ // 判断版本号时先看本机已装的那份(profile 源的对象里带 version)。
364
+ const installedForVersion = source === 'profile' && Array.isArray(context.installed)
365
+ ? context.installed.find((p) => p.name === pick.name)
366
+ : null
367
+ const candidateVersion = String((installedForVersion && installedForVersion.version) || pick.version || pick.spec || '')
368
+ const versionOk = /^[0-9]+\.[0-9]+\.[0-9]+(?:-[0-9A-Za-z.-]+)?$/u.test(candidateVersion) && candidateVersion !== '0.0.0'
369
+ const embedded = format === 'full' || (format === 'hybrid' && (!versionOk || (wantLocal && source === 'profile')))
370
+ if (format === 'hybrid') {
371
+ notes.push(embedded
372
+ ? pick.name + ':没有确定的版本号或要带走本机改动,完整打包(安装时不需要联网)'
373
+ : pick.name + ':只记版本号,安装时联网从市场取包')
374
+ }
375
+ const needPayload = embedded
356
376
  if (source === 'profile') {
357
377
  const installed = context.installed.find((p) => p.name === pick.name)
358
378
  if (!installed) throw new Error('本地找不到插件:' + pick.name)
359
- const loaded = readInstalledPlugin(installed, { maxFileBytes: config?.maxFileBytes, maxTotalBytes: config?.maxPackBytes })
379
+ if (!needPayload) {
380
+ // 只带版本号:读一下 package.json 就够(清单要用 license / peer / engines),不碰几万个文件
381
+ pkg = installed.pkg || null
382
+ payloadDir = installed.dirName || installed.name
383
+ localEdits = false
384
+ }
385
+ const loaded = needPayload ? readInstalledPlugin(installed, { maxFileBytes: config?.maxFileBytes, maxTotalBytes: config?.maxPackBytes }) : { files: [], notes: [], pkg }
360
386
  files = loaded.files
361
387
  pkg = loaded.pkg
362
388
  notes.push(...loaded.notes)
363
389
  payloadDir = installed.dirName || installed.name
364
390
  localEdits = true
365
- if (!wantLocal && typeof pick.download === 'function') {
391
+ if (needPayload && !wantLocal && typeof pick.download === 'function') {
366
392
  // 想打“上游原版”就从 registry 重下,失败则保留本地并标注
367
393
  try {
368
394
  const downloaded = await pick.download(installed.version)
@@ -379,7 +405,21 @@ export async function buildPack(input) {
379
405
  }
380
406
  }
381
407
  } else if (source === 'npm') {
382
- if (typeof pick.download !== 'function') throw new Error('缺少下载器')
408
+ if (!needPayload) {
409
+ const meta = await npmMetadata(pick.name, config, { version: requested })
410
+ const versions = (meta.meta && meta.meta.versions) || {}
411
+ const key = Object.keys(versions)[0] || ''
412
+ pkg = key ? versions[key] : null
413
+ registry = meta.registry || ''
414
+ if (pkg && pkg.dist) {
415
+ tarball = pkg.dist.tarball || ''
416
+ integrity = pkg.dist.integrity || pkg.dist.shasum || ''
417
+ }
418
+ payloadDir = (pkg && pkg.name) || pick.name
419
+ localEdits = false
420
+ if (!pkg) throw new Error('取不到版本信息:' + pick.name)
421
+ } else if (typeof pick.download !== 'function') throw new Error('缺少下载器')
422
+ if (needPayload) {
383
423
  const downloaded = await pick.download(requested)
384
424
  pkg = downloaded.pkg
385
425
  registry = downloaded.registry
@@ -389,6 +429,7 @@ export async function buildPack(input) {
389
429
  payloadDir = dirName
390
430
  files = downloaded.entries.map((e) => ({ name: 'plugins/' + dirName + '/' + e.name, data: e.data }))
391
431
  localEdits = false
432
+ }
392
433
  } else {
393
434
  throw new Error('不支持的来源:' + source)
394
435
  }
@@ -422,6 +463,7 @@ export async function buildPack(input) {
422
463
  hasPatch: Boolean(pkg.dsh && pkg.dsh.bundle && pkg.dsh.bundle.patch),
423
464
  isBundle: Boolean(pkg.dsh && (pkg.dsh.bundle || pkg.dsh.client)),
424
465
  localEdits,
466
+ embedded,
425
467
  mode: localEdits ? 'local' : 'base',
426
468
  configMode: wantConfig ? 'custom' : 'preset',
427
469
  configIncluded: false,
@@ -458,7 +500,8 @@ export async function buildPack(input) {
458
500
 
459
501
  // 配置与数据快照
460
502
  capturedFiles = []
461
- if (options.includeConfig !== false && manifestPlugins.some((plugin) => plugin.configMode === 'custom')) {
503
+ const configAllowed = format !== 'lite'
504
+ if (configAllowed && options.includeConfig !== false && manifestPlugins.some((plugin) => plugin.configMode === 'custom')) {
462
505
  const { captured, notes: configNotes } = captureConfigs(context.patchText || '', manifestPlugins, context.parsePatch)
463
506
  notes.push(...configNotes)
464
507
  for (const plugin of manifestPlugins) {
@@ -549,7 +592,8 @@ export async function buildPack(input) {
549
592
  generator: { name: 'dsh-modpack', version: context.pluginVersion || '0.0.0' },
550
593
  dshVersion: context.dshVersion || '',
551
594
  options: {
552
- includePayload: format === 'full',
595
+ includePayload: format === 'full' || payload.length > 0,
596
+ strategy: format,
553
597
  includeConfig: manifestPlugins.some((plugin) => plugin.configMode === 'custom'),
554
598
  includeLocalEdits: manifestPlugins.some((plugin) => plugin.mode === 'local'),
555
599
  keepLocalOnInstall: options.keepLocal !== false,
package/lib/registry.mjs CHANGED
@@ -24,24 +24,101 @@ export function validatePackageName(name) {
24
24
  return name
25
25
  }
26
26
 
27
- /** 依次尝试每个 registry,第一个成功的算。 */
28
- export async function npmMetadata(name, config) {
27
+ /** npm 的「精简清单」:只带依赖与 dist,体积通常比完整清单小得多。 */
28
+ const META_ACCEPT = 'application/vnd.npm.install-v1+json'
29
+ const EXACT_VERSION_RE = /^[0-9]+\.[0-9]+\.[0-9]+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/u
30
+
31
+ /**
32
+ * 版本清单的体积上限(字节)。
33
+ * billion-context 这类包的清单曾经十几 MB,固定 16 MB 会让它整个装不上,
34
+ * 所以默认放宽到 64 MB,并且允许在设置里调(maxMetadataBytes,单位 MB)。
35
+ */
36
+ export function metadataLimit(config) {
37
+ const mb = Number(config?.maxMetadataBytes)
38
+ if (Number.isFinite(mb) && mb > 0) return Math.max(4, Math.min(512, Math.floor(mb))) * 1024 * 1024
39
+ return 64 * 1024 * 1024
40
+ }
41
+
42
+ /**
43
+ * 取一个包的版本清单,按「精简 → 完整 → 单版本」三层退让。
44
+ *
45
+ * 为什么不是一条路:vnd.npm.install-v1+json 通常最小,但个别包反而更大;
46
+ * 完整清单有时更小;而只要调用方知道确切版本,/name/1.2.3 这条 REST 永远最小。
47
+ * 三层都失败才算失败,错误信息里带上每层的原因,方便看出是被体积挡住还是网络。
48
+ */
49
+ /**
50
+ * 快速探一下 registry 通不通(npm 的 /-/ping 很轻)。
51
+ * 用来决定「懒人包要不要先按市场版本装」:没网就直接用包里自带的,
52
+ * 免得每个插件都等一遍超时,装个包要好几分钟。
53
+ */
54
+ export async function probeRegistry(config, timeoutMs = 4000) {
55
+ const registries = Array.isArray(config && config.registries) && config.registries.length
56
+ ? config.registries
57
+ : ['https://registry.npmjs.org']
58
+ let last = null
59
+ for (const base of registries.slice(0, 2)) {
60
+ try {
61
+ const url = String(base).replace(/\/+$/u, '') + '/-/ping'
62
+ await requestJson(url, config, { maxBytes: 64 * 1024, timeoutMs, retries: 0 })
63
+ return true
64
+ } catch (error) {
65
+ last = error
66
+ }
67
+ }
68
+ return false
69
+ }
70
+
71
+ export async function npmMetadata(name, config, options = {}) {
29
72
  validatePackageName(name)
30
73
  const registries = Array.isArray(config?.registries) && config.registries.length > 0
31
74
  ? config.registries
32
75
  : ['https://registry.npmjs.org']
76
+ const limit = metadataLimit(config)
77
+ const wanted = typeof options.version === 'string' ? options.version.trim() : ''
78
+ const exact = EXACT_VERSION_RE.test(wanted) ? wanted : ''
33
79
  const errors = []
34
80
  for (const base of registries) {
35
- try {
36
- const url = base.replace(/\/+$/u, '') + '/' + encodeURIComponent(name).replace(/^%40/u, '@')
37
- const meta = await fetchJson(url, config, { accept: 'application/json' })
38
- if (!meta || typeof meta !== 'object' || !meta.versions) throw new Error('元数据缺少 versions')
39
- return { meta, registry: base.replace(/\/+$/u, '') }
40
- } catch (error) {
41
- errors.push(base + ' → ' + String(error?.message || error))
81
+ const root = base.replace(/\/+$/u, '')
82
+ const url = root + '/' + encodeURIComponent(name).replace(/^%40/u, '@')
83
+ const attempts = [
84
+ { label: '精简清单', target: url, accept: META_ACCEPT, maxBytes: limit, full: false },
85
+ { label: '完整清单', target: url, accept: 'application/json', maxBytes: limit, full: true },
86
+ ]
87
+ if (options.full === true) attempts.reverse()
88
+ if (exact) {
89
+ attempts.push({
90
+ label: '单版本清单',
91
+ target: url + '/' + encodeURIComponent(exact),
92
+ accept: 'application/json',
93
+ maxBytes: Math.min(limit, 8 * 1024 * 1024),
94
+ version: exact,
95
+ })
96
+ }
97
+ for (const attempt of attempts) {
98
+ try {
99
+ const doc = await fetchJson(attempt.target, config, { accept: attempt.accept, maxBytes: attempt.maxBytes, timeoutMs: 45000 })
100
+ if (attempt.version) {
101
+ if (!doc || typeof doc !== 'object' || !doc.version) throw new Error('没有版本信息')
102
+ return {
103
+ meta: { 'dist-tags': { latest: doc.version }, versions: { [doc.version]: doc }, time: {} },
104
+ registry: root,
105
+ doc: 'version',
106
+ }
107
+ }
108
+ if (!doc || typeof doc !== 'object' || !doc.versions || Object.keys(doc.versions).length === 0) {
109
+ throw new Error('元数据缺少 versions')
110
+ }
111
+ return { meta: doc, registry: root, doc: attempt.full ? 'full' : 'abbrev' }
112
+ } catch (error) {
113
+ errors.push(root + '(' + attempt.label + ')→ ' + String((error && error.message) || error))
114
+ }
42
115
  }
43
116
  }
44
- throw new Error('registry 都失败了:' + errors.join(';'))
117
+ const oversize = errors.some((line) => /超过上限/u.test(line))
118
+ const hint = oversize
119
+ ? '(版本清单太大:可在设置里把 maxMetadataBytes 调大,或改用确定的版本号,插件会直接取单版本清单)'
120
+ : ''
121
+ throw new Error('registry 都失败了:' + errors.join(';') + hint)
45
122
  }
46
123
 
47
124
  /** 选版本:精确版 > dist-tags.latest > 范围里最高的稳定版。 */
@@ -74,7 +151,7 @@ export function relativeTime(iso) {
74
151
  * @returns {Promise<{name, version, registry, tarball, integrity, sha256, license, repository, pkg, entries, files, unpackedBytes}>}
75
152
  */
76
153
  export async function downloadPackage(name, spec, config) {
77
- const { meta, registry } = await npmMetadata(name, config)
154
+ const { meta, registry } = await npmMetadata(name, config, { version: spec })
78
155
  const version = pickVersion(meta, spec)
79
156
  const manifest = meta.versions[version]
80
157
  if (!manifest || !manifest.dist || !manifest.dist.tarball) throw new Error('版本 ' + version + ' 没有 tarball')
package/lib/store.mjs CHANGED
@@ -33,6 +33,8 @@ export const HOSTS_VERSION = 2
33
33
  export const NET_VERSION = 2
34
34
 
35
35
  export const DEFAULT_CONFIG = {
36
+ // 插件页标题旁那句定位语;市场条目描述开头也用同一句(见 dev/marketplace-awesome-dsh-plugin.yml)
37
+ tagline: '谁说dsh不能整整合包呢?(你说这几个插件整一块不牛逼坏了)',
36
38
  profile: '',
37
39
  packDir: '',
38
40
  vendorDir: '',
@@ -61,6 +63,9 @@ export const DEFAULT_CONFIG = {
61
63
  netRetries: 1,
62
64
  curlFallback: true,
63
65
  maxDownloadBytes: 256 * 1024 * 1024,
66
+ // 版本清单(packument)的体积上限,单位 MB。
67
+ // 有的包清单十几 MB(billion-context 曾经超过 16 MB),旧版固定 16 MB 会直接装不上。
68
+ maxMetadataBytes: 64,
64
69
  maxPackBytes: 256 * 1024 * 1024,
65
70
  maxFileBytes: 16 * 1024 * 1024,
66
71
  // 进度窗里「收尾」的记录留多久(秒):0 = 留到 DSH 下次启动(或手动清空);给正数就按秒自动清
@@ -128,6 +133,10 @@ export function clampConfig(raw) {
128
133
  cfg.maxPackBytes = Math.min(4096 * oneMb, Math.max(16 * oneMb, Math.floor(Number(cfg.maxPackBytes) || DEFAULT_CONFIG.maxPackBytes)))
129
134
  cfg.maxFileBytes = Math.min(256 * oneMb, Math.max(1 * oneMb, Math.floor(Number(cfg.maxFileBytes) || DEFAULT_CONFIG.maxFileBytes)))
130
135
  cfg.maxDownloadBytes = Math.min(4096 * oneMb, Math.max(16 * oneMb, Math.floor(Number(cfg.maxDownloadBytes) || DEFAULT_CONFIG.maxDownloadBytes)))
136
+ // 版本清单上限:4~512 MB,默认 64
137
+ cfg.maxMetadataBytes = Math.min(512, Math.max(4, Math.floor(Number(cfg.maxMetadataBytes) || DEFAULT_CONFIG.maxMetadataBytes)))
138
+ // 定位语:一句话,别让它变成一篇文章
139
+ cfg.tagline = String(cfg.tagline || DEFAULT_CONFIG.tagline).slice(0, 120)
131
140
  // 进度窗位置不在这里管:它由界面自己拖动并存在浏览器本地,服务端不需要知道
132
141
  // 打包前安全检测是强制的:设置里怎么写都不认,打包一律扫。
133
142
  cfg.scanBeforePack = true
@@ -186,6 +195,20 @@ export function appendHistory(entry, limit = DEFAULT_CONFIG.historyLimit) {
186
195
  return list
187
196
  }
188
197
 
198
+ /** 清空最近记录(文件留着,只是写成空数组)。 */
199
+ export function clearHistory() {
200
+ writeJsonAtomic(pathsFor({}).history, [])
201
+ return []
202
+ }
203
+
204
+ /** 删掉一条最近记录:按 at 时间戳匹配(每条只有这一个稳定标识)。 */
205
+ export function removeHistory(at) {
206
+ const stamp = String(at || '')
207
+ const list = readHistory().filter((item) => String((item && item.at) || '') !== stamp)
208
+ writeJsonAtomic(pathsFor({}).history, list)
209
+ return list
210
+ }
211
+
189
212
  export function appendLog(line) {
190
213
  try {
191
214
  fs.mkdirSync(pluginHome(), { recursive: true })
package/locale/en.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "meta": {
3
3
  "title": "Modpack Kit",
4
- "description": "HMCL/PCL-style modpack packaging for DeepSeek Harness: bundle several plugins with their configuration and data into one .dshpack and install it in a single pass. A full pack installs on a machine that only has DSH; a lite pack records names and versions and fetches them from the plugin market on install. Each plugin is packed as a preset (default configuration) or custom (local configuration and data, credentials redacted), configuration is re-applied by entry, and existing data files are never overwritten by default. Packing always scans for secrets and risky code in memory (masked, never written to disk); high-risk hits pause the job until confirmed, then it resumes from the checkpoint. Installation re-checks sha256 integrity, compatibility and licences, and can finish without enabling. Categories, search, paging and plugin groups come from the plugin market; groups collapse and can be added in one click. The UI can live in settings, the sidebar or the plugins tab. The plugin market is recommended, not required.",
4
+ "description": "Who says DSH cannot do modpacks? (Put these plugins together and it is genuinely good.) Bundle DeepSeek Harness plugins with their config and data into one .dshpack: one-click install, works offline, three strategies, groups share the plugin market. npm: https://www.npmjs.com/package/dsh-modpack-kit",
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 本体即可安装)与轻量包(只记插件名与版本,安装时按版本从插件市场取包);每个插件单独选「插件预设」或「自定义配置」,配置按条目回填、数据写回且默认不覆盖已有文件,疑似凭据替换为 ${REDACTED}。打包前强制检查敏感信息与风险代码(命中只留掩码、原文不落盘),高风险先停在「等决定」,确认后从检测点续跑;安装前校验 sha256 完整性、兼容性与许可证,装完可选先不启用。分类、搜索、分页与插件市场目录同源,本机插件按市场的分组折叠展示、组头可一键加入或清空本组;三处入口(设置 / 侧边栏 / 插件页)各自独立开关。建议先装插件市场(dshmarket),但不是必须。",
4
+ "description": "谁说dsh不能整整合包呢?(你说这几个插件整一块不牛逼坏了) 把多个 DeepSeek Harness 插件连同配置与数据打成一个 .dshpack,一键安装、离线可装;三种策略、分组同源插件市场。npm:https://www.npmjs.com/package/dsh-modpack-kit",
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.9",
4
- "description": "HMCL/PCL-style modpack packaging for DeepSeek Harness: bundle several plugins with their configuration and data into one .dshpack and install it in a single pass. A full pack installs on a machine that only has DSH; a lite pack records names and versions and fetches them from the plugin market on install. Each plugin is packed as a preset (default configuration) or custom (local configuration and data, credentials redacted), configuration is re-applied by entry, and existing data files are never overwritten by default. Packing always scans for secrets and risky code in memory (masked, never written to disk); high-risk hits pause the job until confirmed, then it resumes from the checkpoint. Installation re-checks sha256 integrity, compatibility and licences, and can finish without enabling. Categories, search, paging and plugin groups come from the plugin market; groups collapse and can be added in one click. The UI can live in settings, the sidebar or the plugins tab. The plugin market is recommended, not required.",
3
+ "version": "0.2.0-1",
4
+ "description": "谁说dsh不能整整合包呢?(你说这几个插件整一块不牛逼坏了) 把多个 DeepSeek Harness 插件连同配置与数据打成一个 .dshpack,一键安装、离线可装;三种策略、分组同源插件市场。npm:https://www.npmjs.com/package/dsh-modpack-kit",
5
5
  "type": "module",
6
6
  "main": "index.js",
7
7
  "exports": {
@@ -30,7 +30,14 @@
30
30
  "pack",
31
31
  "installer",
32
32
  "plugin-manager",
33
- "security-scan"
33
+ "security-scan",
34
+ "dsh",
35
+ "deepseek-harness",
36
+ "dshpack",
37
+ "plugin-bundle",
38
+ "one-click-install",
39
+ "offline-install",
40
+ "migrate-plugins"
34
41
  ],
35
42
  "license": "PolyForm-Noncommercial-1.0.0",
36
43
  "author": "Vesna-Strivozha-cn",