dsh-crate 0.5.1 → 0.5.3

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/patch.js CHANGED
@@ -579,7 +579,13 @@ export function packagePatchFlags(host, profileDirectory, names, state) {
579
579
  // host, so it is not a decision about this package (#1113): the shape a
580
580
  // package rename leaves behind.
581
581
  const applies = (id) => rowFlagApplies(state, id, composedRowName(host, id));
582
- if (rows.some(id => decidedByUser(id) && applies(id) && state.disables.includes(id)))
582
+ // A package counts as off only when nothing of it is left running: a
583
+ // multi-component plugin with some components switched off is still on
584
+ // (#1150). One disabled row used to flip the whole package, which kept
585
+ // it out of 「全部更新」.
586
+ // Rows that name another module do not count either way (#1113).
587
+ const decidedRows = rows.filter(id => decidedByUser(id) && applies(id));
588
+ if (decidedRows.length > 0 && decidedRows.every(id => state.disables.includes(id)))
583
589
  disabled.push(name);
584
590
  if (rows.some(id => decidedByUser(id) && applies(id) && state.forced.includes(id)))
585
591
  forced.push(name);
@@ -251,6 +251,127 @@ function storesFromNdjson(output) {
251
251
  function storeVersionSegment(path) {
252
252
  return path === undefined ? undefined : /[/\\](v\d+)[/\\]*$/.exec(path)?.[1];
253
253
  }
254
+ function readStorePin(profileDirectory) {
255
+ if (profileDirectory === undefined)
256
+ return null;
257
+ let yaml;
258
+ try {
259
+ yaml = readFileSync(join(profileDirectory, 'pnpm-workspace.yaml'), 'utf8');
260
+ }
261
+ catch {
262
+ return null;
263
+ }
264
+ const camel = /^storeDir:[ \t]*['"]?([^'"\r\n]+?)['"]?[ \t]*$/mu.exec(yaml);
265
+ if (camel !== null)
266
+ return { path: camel[1].trim(), honoured: true };
267
+ const kebab = /^store-dir:[ \t]*['"]?([^'"\r\n]+?)['"]?[ \t]*$/mu.exec(yaml);
268
+ return kebab === null ? null : { path: kebab[1].trim(), honoured: false };
269
+ }
270
+ /**
271
+ * The store pnpm takes from the environment, which outranks the profile's
272
+ * own pnpm-workspace.yaml.
273
+ *
274
+ * Measured on pnpm 11.28.5 with a profile pinning one store: setting
275
+ * `PNPM_CONFIG_STORE_DIR` (or the lowercase `pnpm_config_store_dir`) to
276
+ * another path made `pnpm store path` print that other path. `npm_config_
277
+ * store_dir` did NOT — verified twice, with and without a workspace pin — so
278
+ * it is deliberately not read here: naming a variable that changes nothing
279
+ * would send the reader to the wrong place.
280
+ */
281
+ function storeFromEnvironment() {
282
+ for (const [name, value] of Object.entries(process.env)) {
283
+ if (value !== undefined && value !== '' && /^pnpm_config_store_dir$/iu.test(name))
284
+ return { name, value };
285
+ }
286
+ return null;
287
+ }
288
+ /** Two store paths the same, tolerating separator style and Windows case. */
289
+ function sameStorePath(left, right) {
290
+ const normalise = (path) => path.replace(/\\/gu, '/').replace(/\/+$/u, '').toLowerCase();
291
+ return normalise(left) === normalise(right);
292
+ }
293
+ /**
294
+ * The way out of ERR_PNPM_UNEXPECTED_STORE, said in terms of the layer that
295
+ * actually decides the store (#244, #715; the layer order below was measured).
296
+ *
297
+ * The old text told every user the same thing: write the recorded store into
298
+ * the profile's pnpm-workspace.yaml. That is right for exactly one of the
299
+ * shapes this error has, and wrong — silently, repeatedly — for the others:
300
+ *
301
+ * - the file may already carry that line, in which case repeating the advice
302
+ * is a loop (the reporter's profile had it, and the fix that worked was
303
+ * elsewhere);
304
+ * - it may carry the kebab spelling, which pnpm ignores with a warning;
305
+ * - it may carry a DIFFERENT path from the record, so following "write the
306
+ * recorded store" means first seeing the two disagree;
307
+ * - an environment variable outranks the file, so on those machines the
308
+ * advice cannot work at all until the variable is changed;
309
+ * - the recorded store may no longer exist (the drive was moved or removed),
310
+ * and pinning a dead path is worse than the error it replaces.
311
+ *
312
+ * Each of those is readable from files and the environment the market already
313
+ * has, so the message can name the one that applies — and give a command that
314
+ * proves the result, since this is the branch where "I followed the advice and
315
+ * nothing changed" has been the actual experience.
316
+ */
317
+ function storeRelinkAdvice(linked, wanted, profileDirectory) {
318
+ const pin = readStorePin(profileDirectory);
319
+ const env = storeFromEnvironment();
320
+ const envWins = env !== null && !sameStorePath(env.value, linked);
321
+ const wantedZh = wanted ?? '(上面列出的那个)';
322
+ const wantedEn = wanted ?? 'the one listed above';
323
+ const paste = `storeDir: '${linked}'`;
324
+ const verifyZh = '改完先在 profile 目录里执行 `pnpm store path` 验证:它必须**正好**打印上面第一个路径;打出别的就说明这一行没有生效,先别急着重试。';
325
+ const verifyEn = 'Verify before retrying: run `pnpm store path` in the profile directory — it must print the first path above, exactly. Anything else means that line did not take effect.';
326
+ const envZh = env === null ? '' : `(当前环境里 ${env.name}=${env.value})`;
327
+ const envEn = env === null ? '' : ` (currently ${env.name}=${env.value} in this environment)`;
328
+ const ladderZh = 'pnpm 解析 store 的优先级(高→低):--store-dir 命令行参数 → 环境变量 PNPM_CONFIG_STORE_DIR → profile 的 pnpm-workspace.yaml → 全局 pnpm 配置(`pnpm config get store-dir` 看到的就是它)→ 默认位置。';
329
+ const ladderEn = "The order pnpm resolves a store in (highest first): the --store-dir flag → the environment variable PNPM_CONFIG_STORE_DIR → the profile's pnpm-workspace.yaml → the global pnpm config (what `pnpm config get store-dir` reports) → the default location.";
330
+ // The file already names the recorded store and the error is still here:
331
+ // repeating the advice cannot help. Say which layer outranked it. Checked
332
+ // before the "different path" case, because same-path-plus-still-failing is
333
+ // the loop this branch exists to end.
334
+ if (pin !== null && pin.honoured && sameStorePath(pin.path, linked)) {
335
+ const causeZh = envWins
336
+ ? `**上面那个环境变量把它覆盖了**:${env.name}=${env.value} 比 profile 文件优先,所以把 storeDir 改多少遍都没有用。`
337
+ : '覆盖它的是更高优先级的一层,而这个文件本身已经没有可改的地方了。';
338
+ const causeEn = envWins
339
+ ? `**The environment variable above overrides it**: ${env.name}=${env.value} outranks the profile file, so editing storeDir there changes nothing.`
340
+ : 'A higher-priority layer overrides it, and there is nothing left to change in this file.';
341
+ return {
342
+ zh: `profile 的 pnpm-workspace.yaml 已经写了 storeDir: '${pin.path}'(就是记录里的那个 store),pnpm 却仍然解析到 ${wantedZh}:这说明这一行被更高优先级的东西压住了,再改这个文件不会有任何效果。${causeZh}${ladderZh}把上面那一层改成这个路径,或者去掉它让文件生效${envWins ? `(在这个环境里,去掉 ${env.name} 往往比改它更省事)` : ''}。${verifyZh}`,
343
+ en: `the profile's pnpm-workspace.yaml already pins storeDir: '${pin.path}' — the recorded store — yet pnpm still resolves ${wantedEn}, so a higher-priority layer overrides the file and editing it cannot help. ${causeEn} ${ladderEn} Change that layer to this path, or remove it so the file applies${envWins ? ` (in this environment, dropping ${env.name} is usually simpler than rewriting it)` : ''}. ${verifyEn}`,
344
+ };
345
+ }
346
+ // A pin in the file that names something else: the file beats the global
347
+ // config, so the line is the right seat for the fix — but it must be
348
+ // corrected rather than added a second time.
349
+ if (pin !== null && pin.honoured && !envWins) {
350
+ return {
351
+ zh: `profile 的 pnpm-workspace.yaml 里写的是 storeDir: '${pin.path}',但 node_modules 记录的是上面第一个路径——两处不一致,pnpm 会按文件里的走,于是继续对不上。把这一行改成记录里的那个路径:\n\n ${paste}\n\n${verifyZh}`,
352
+ en: `the profile's pnpm-workspace.yaml pins storeDir: '${pin.path}' while node_modules records the first path above, so pnpm follows the file and still disagrees with the record. Change that line to the recorded path:\n\n ${paste}\n\n${verifyEn}`,
353
+ };
354
+ }
355
+ // The file pins something in a spelling this pnpm does not read.
356
+ if (pin !== null && !pin.honoured) {
357
+ return {
358
+ zh: `profile 的 pnpm-workspace.yaml 里写的是 kebab 写法 store-dir: '${pin.path}'——pnpm **不认这个键**(它只在 stderr 留一行 WARN,然后当作没写,pnpm 11.28 实测),所以现在解析到的还是 ${wantedZh}。改成驼峰写法(单引号,Windows 路径在双引号里会被当成转义):\n\n ${paste}\n\n${envWins ? `另外,${env.name}=${env.value} 的优先级比这个文件更高,它还在的时候这一行同样不起作用。` : ''}${verifyZh}`,
359
+ en: `the profile's pnpm-workspace.yaml spells it the kebab way, store-dir: '${pin.path}' — a key this pnpm does **not** read (it prints one WARN to stderr and behaves as if the line were absent; measured on 11.28.5), so pnpm still resolves ${wantedEn}. Use the camelCase key with single quotes (a Windows path in double quotes is read as escape sequences):\n\n ${paste}\n\n${envWins ? `Also, ${env.name}=${env.value} outranks this file, so the line still would not apply while it is set. ` : ''}${verifyEn}`,
360
+ };
361
+ }
362
+ // Nothing pinned yet: the ordinary case. When the environment is what pnpm
363
+ // obeys, that is the layer to change — the file loses to it unconditionally.
364
+ if (envWins) {
365
+ return {
366
+ zh: `现在生效的是**环境变量**${envZh},它比 profile 的 pnpm-workspace.yaml 优先——文件里的 storeDir 写了也会被它压住,所以改那个文件没有任何作用。要改的是这一层:把 ${env.name} 指向上面第一个路径,或者去掉它(让 pnpm 回到全局配置 / 默认位置),然后再验证。${ladderZh}${verifyZh}`,
367
+ en: `the store in effect comes from **the environment**${envEn}, which outranks the profile's pnpm-workspace.yaml — a storeDir written there is overridden, so editing that file cannot work. Change this layer instead: point ${env.name} at the first path above, or remove it (letting pnpm fall back to the global config / default), then verify. ${ladderEn}${verifyEn}`,
368
+ };
369
+ }
370
+ return {
371
+ zh: `持久的修法:把**记录里的那个** store 写进 profile 的 pnpm-workspace.yaml,顶层、驼峰、单引号(Windows 路径在双引号里会被当成转义,整份文件会读不了):\n\n ${paste}\n\n加完不用重装任何东西——包本来就在那个 store 里,直接重试即可(dsh 正在运行可能占用文件,必要时先退出 dsh)。${verifyZh}如果那个路径其实已经不存在了(盘换了、目录被删),写它只会把 profile 钉在一个空 store 上,那就只能改用 pnpm 现在解析出的这个(包要重新下载)。`,
372
+ en: `durable fix: write the store from the RECORD into the profile's pnpm-workspace.yaml, top level, camelCase, single quotes (a Windows path in double quotes is read as escape sequences and the whole file fails to parse):\n\n ${paste}\n\nNothing has to be reinstalled — the packages are already in that store, so just retry (stop dsh first if it holds the files open). ${verifyEn}If that path no longer exists (the drive changed, the directory was deleted), pinning it would tie the profile to an empty store — adopt the store pnpm now resolves instead (every package is downloaded again).`,
373
+ };
374
+ }
254
375
  export function classifyPnpmFailure(output, exitCode, context) {
255
376
  // #817: the host's silence watchdog (@deepseek-ai/dsh-plugin-manager,
256
377
  // `idleTimeoutMs`, 10 minutes by default) killed pnpm. Checked first: it is
@@ -311,6 +432,27 @@ export function classifyPnpmFailure(output, exitCode, context) {
311
432
  // a repair that goes wrong here leaves a profile in worse shape than the
312
433
  // clear error it replaced. The paths are in the message; the choice is
313
434
  // the user's.
435
+ //
436
+ // Measured on pnpm 11.28.5 (2026-11), for the #1100 report, the layer order
437
+ // that advice depends on
438
+ // (a scratch workspace and `pnpm store path`, each layer set alone and then
439
+ // against the others, because the previous sentence had not been re-checked
440
+ // since #715 and #244 were filed):
441
+ // --store-dir > PNPM_CONFIG_STORE_DIR > pnpm-workspace.yaml `storeDir`
442
+ // > the global npmrc `store-dir` > the default.
443
+ // Three things follow, and the message now states them instead of assuming
444
+ // the middle layer is always the one that decides:
445
+ // - the camelCase key IS honoured (#715), the kebab `store-dir` is NOT:
446
+ // pnpm prints `…ignored because they are not written in camelCase` on
447
+ // stderr and resolves exactly as if the line were absent;
448
+ // - an environment variable outranks the profile file, so a user who
449
+ // relocated the store that way cannot fix it in the profile at all —
450
+ // the advice has to name the variable (storeRelinkAdvice does);
451
+ // - a project `.npmrc` is ignored, the global one is not, so "the npmrc"
452
+ // is the global file and `pnpm config get store-dir` names its value.
453
+ // Each shape also gets a check the user can run (`pnpm store path`), since
454
+ // this branch's real-world failure was "I wrote exactly what it said and
455
+ // the next run failed the same way".
314
456
  if (output.includes('ERR_PNPM_UNEXPECTED_STORE')) {
315
457
  const ndjson = storesFromNdjson(output);
316
458
  // pnpm 12's default reporter wraps long lines, inside the quotes too.
@@ -368,10 +510,22 @@ export function classifyPnpmFailure(output, exitCode, context) {
368
510
  message: `这个 profile 的 node_modules 是用另一个大版本的 pnpm${named} 建的,而正在跑的这个 pnpm 大版本不同:它会在任何 storeDir 下面再拼自己的版本目录(上面第二个路径末尾那一段),所以**写 storeDir 修不好**,自动回滚也会以同样的方式失败。${detail}\n出路(任选):\n 1) 用建这份 node_modules 的那个 pnpm 大版本重新执行——${recorded === null ? '版本号写在 profile 的 node_modules/.modules.yaml 里(packageManager)' : `即 pnpm ${recorded}`},装好后让它排在 PATH 前面;\n 2) 或者留在这个新大版本上,清空 node_modules 重新安装(包会重新下载)。 / this profile's node_modules was built by a different pnpm${named === '' ? '' : ` (${recorded})`} major than the one now running: pnpm appends its own store-version segment under whatever storeDir says (the second path above ends with it), so **writing storeDir cannot fix this**, and the automatic rollback fails the same way.${detail}\nTwo ways out: 1) run the pnpm major that built this node_modules — ${recorded === null ? 'its version is recorded in the profile’s node_modules/.modules.yaml (packageManager)' : `pnpm ${recorded}`} — with it ahead of the current one on PATH; or 2) stay on the new major and reinstall node_modules from scratch (every package is downloaded again).`,
369
511
  };
370
512
  }
513
+ // The paths pnpm names are the whole diagnosis, so when its wording
514
+ // changes and they cannot be read, say so instead of inventing them — and
515
+ // still leave the reader with the key (`storeDir`) and the check
516
+ // (`pnpm store path`), because an unreadable path is not a missing remedy.
517
+ if (linked === undefined) {
518
+ return {
519
+ code: 'unexpected-store',
520
+ recoverable: false,
521
+ message: `这个 profile 的 node_modules 链接到的 pnpm store,和 pnpm 现在解析出的 store 不是同一个,pnpm 因此拒绝这个 profile 的所有安装与卸载。这次没能从 pnpm 的输出里读出两个路径(它的措辞变了),请按上面的原文核对。修法是在 profile 的 pnpm-workspace.yaml 里用驼峰 \`storeDir\` 指定记录里的那个 store(单引号),改完用 \`pnpm store path\` 验证;注意环境变量 PNPM_CONFIG_STORE_DIR 比这个文件优先,而 kebab 写法 \`store-dir\` 会被 pnpm 忽略。\`pnpm install --store-dir\` 不是修复。 / this profile's node_modules is linked to a different pnpm store than the one pnpm now resolves, so pnpm refuses every install and uninstall for it. This time the two paths could not be read from pnpm's output (its wording changed) — check the text above. The fix is to name the recorded store in the profile's pnpm-workspace.yaml under the camelCase key \`storeDir\` (single-quoted), then verify with \`pnpm store path\`; note that the environment variable PNPM_CONFIG_STORE_DIR outranks that file, and the kebab spelling \`store-dir\` is ignored. \`pnpm install --store-dir\` is not a fix.`,
522
+ };
523
+ }
524
+ const advice = storeRelinkAdvice(linked, wanted, context?.profileDirectory);
371
525
  return {
372
526
  code: 'unexpected-store',
373
527
  recoverable: false,
374
- message: `这个 profile 的 node_modules 链接到的 pnpm store,和 pnpm 现在解析出的 store 不是同一个,pnpm 因此拒绝这个 profile 的所有安装与卸载。典型触发是把 $DSH_HOME 迁到另一个挂载点:迁盘前建的 node_modules 记着旧盘上的 store,而 pnpm 会按新的挂载点自动改选一个(#244 的另一种触发,见 #715)。${detail}\n持久的修法:把**记录里的那个** store 写进 profile 的 pnpm-workspace.yaml(顶层、驼峰):\n\n storeDir: <上面第一个路径>\n\n加完不用重装任何东西——包本来就在那个 store 里,直接重试即可(dsh 运行时可能占用文件,必要时先退出 dsh)。\n注意 \`pnpm install --store-dir <路径>\` **不是修复**:它只对那一次命令生效,也不会改写 node_modules/.modules.yaml 里的记录,所以下一条命令会报同样的错(pnpm 11.7 与 11.22 实测)。\n想改用 pnpm 现在解析出的那个 store 也行,但那要求清空并重装整个 node_modules(包全部重新下载),代价由你决定。 / this profile's node_modules is linked to a different pnpm store than the one pnpm now resolves, so pnpm refuses every install and uninstall for it. The usual trigger is moving $DSH_HOME to another mount point: a node_modules built before the move records the old disk's store while pnpm re-selects one for the new mount.${detail}\nDurable fix: write the store from the RECORD into the profile's pnpm-workspace.yaml (top level, camelCase):\n\n storeDir: <the first path above>\n\nNothing has to be reinstalled — the packages are already in that store — so just retry (stop dsh first if files are locked).\nNote that \`pnpm install --store-dir <path>\` is NOT a fix: it applies to that one command and does not rewrite the record in node_modules/.modules.yaml, so the next command fails exactly the same way (measured on pnpm 11.7 and 11.22).\nSwitching to the store pnpm now resolves is also possible, but it requires purging and reinstalling the whole node_modules (every package re-downloaded) — your call, not the market's.`,
528
+ message: `这个 profile 的 node_modules 链接到的 pnpm store,和 pnpm 现在解析出的 store 不是同一个,pnpm 因此拒绝这个 profile 的所有安装与卸载。典型触发是把 $DSH_HOME 或 pnpm 的 store 移到另一个盘:搬迁前建的 node_modules 记着旧盘上的 store,而 pnpm 会按新位置另选一个(#244 的另一种触发,见 #715)。${detail}\n${advice.zh}\n注意 \`pnpm install --store-dir <路径>\` **不是修复**:它只对那一次命令生效,也不会改写 node_modules/.modules.yaml 里的记录,所以下一条命令会报同样的错(pnpm 11.7 与 11.22 实测)。想改用 pnpm 现在解析出的那个 store 也行,但那要求清空并重装整个 node_modules(包全部重新下载),代价由你决定。 / this profile's node_modules is linked to a different pnpm store than the one pnpm now resolves, so pnpm refuses every install and uninstall for it. The usual trigger is moving $DSH_HOME or the pnpm store to another drive: a node_modules built before the move records the old disk's store while pnpm selects one for the new location (the other trigger for #244, see #715).${detail}\n${advice.en}\nNote that \`pnpm install --store-dir <path>\` is NOT a fix: it applies to that one command and does not rewrite the record in node_modules/.modules.yaml, so the next command fails exactly the same way (measured on pnpm 11.7 and 11.22). Switching to the store pnpm now resolves is also possible, but it requires purging and reinstalling the whole node_modules (every package re-downloaded) — your call, not the market's.`,
375
529
  };
376
530
  }
377
531
  // #367: pnpm verifies every tarball resolution in the lockfile before it
package/lib/profile.js CHANGED
@@ -1891,11 +1891,14 @@ function readReleaseAgeBlock(file) {
1891
1891
  * nothing in the file says which main package it belongs to — guessing would
1892
1892
  * delete policy that may still be in effect for something installed.
1893
1893
  *
1894
+ * With `keepVersion` (the update path) the rows that name that version are
1895
+ * kept and only the older ones go.
1896
+ *
1894
1897
  * @returns the entries removed, for the caller to log; empty when there is no
1895
1898
  * such block, no such row, or the file cannot be read exactly (in which case
1896
1899
  * it is left byte-for-byte as it was).
1897
1900
  */
1898
- export function dropReleaseAgeExcludes(profile, name, explicitDir) {
1901
+ export function dropReleaseAgeExcludes(profile, name, explicitDir, keepVersion) {
1899
1902
  const block = readReleaseAgeBlock(join(profileDir(profile, explicitDir), 'pnpm-workspace.yaml'));
1900
1903
  if (block === null)
1901
1904
  return [];
@@ -1906,6 +1909,19 @@ export function dropReleaseAgeExcludes(profile, name, explicitDir) {
1906
1909
  return [item.line];
1907
1910
  if (item.rule.name !== name)
1908
1911
  return [item.original];
1912
+ // After an update (#1093) only rows that do not name the installed version
1913
+ // are stale. A row that names it stays whole — it may be the one pnpm just
1914
+ // wrote for this very update, which the next install's age check needs. A
1915
+ // union that also lists older versions stays too: it is kept or dropped as
1916
+ // written, never rewritten, so nothing here can loosen the gate. A bare
1917
+ // name already covers every version; that is a policy someone chose, not a
1918
+ // leftover.
1919
+ if (keepVersion !== undefined) {
1920
+ if (item.rule.selector === null)
1921
+ return [item.original];
1922
+ if (item.rule.selector.split('||').some(version => version.trim() === keepVersion))
1923
+ return [item.original];
1924
+ }
1909
1925
  dropped.push(item.rule.selector === null ? item.rule.name : `${item.rule.name}@${item.rule.selector}`);
1910
1926
  return [];
1911
1927
  });
@@ -19,9 +19,16 @@ export function catalogReleaseSourceOf(spec, entry) {
19
19
  if (url.protocol !== 'https:' || url.host !== 'github.com' || url.username !== '' || url.password !== '' || url.search !== '' || url.hash !== '')
20
20
  return null;
21
21
  }
22
- const match = /^\/([^/]+\/[^/]+)\/releases\/(?:latest\/download|download\/[^/]+)\/([^/]+)$/.exec(installed.pathname);
23
- if (match === null || match[1].toLowerCase() !== source.repo.toLowerCase() || match[2] !== asset)
22
+ const match = /^\/([^/]+\/[^/]+)\/releases\/(?:latest\/download|download\/([^/]+))\/([^/]+)$/.exec(installed.pathname);
23
+ if (match === null || match[1].toLowerCase() !== source.repo.toLowerCase())
24
24
  return null;
25
+ const [, , tag, installedAsset] = match;
26
+ if (installedAsset !== asset) {
27
+ // A legacy filename can only add the version from its own stable release tag.
28
+ const version = /^v?(\d+\.\d+\.\d+)$/.exec(tag ?? '')?.[1];
29
+ if (version === undefined || installedAsset !== asset.replace(/\.(?:tgz|tar\.gz)$/, extension => `-${version}${extension}`))
30
+ return null;
31
+ }
25
32
  return { repo: source.repo, asset, manifest: source.subpath === null ? 'package.json' : `${source.subpath}/package.json` };
26
33
  }
27
34
  catch {
package/lib/routes.js CHANGED
@@ -722,6 +722,38 @@ export function mountMarketRoutes(host, config, commandRuntime, agentsLookup, ho
722
722
  return;
723
723
  logEvent('warn', 'toggle', `${name}: kept off by this market's own record, while ${homePatchPath} enables it — that layer is not the one the market writes, so the market will not follow it. Move the row into this profile's cordis.patch.yml to make it stick (#519)`);
724
724
  }
725
+ /**
726
+ * Replay one switched-off package at boot, carrier-safe.
727
+ *
728
+ * The disable list only names a package, while a CARRIER bundle's patch
729
+ * also rewires foreign rows: it disables stock rows or gives them an
730
+ * `inject:` for a service the bundle's own gate entry provides. Disabling
731
+ * every matching entry would stop that gate too (the gate entry's name is
732
+ * `<pkg>/<row>`, so it matches the package), and the foreign rows would
733
+ * wait forever for a service that no longer exists — every preset pending.
734
+ *
735
+ * While such a bundle still sits in dsh.profile.bundles (an interrupted or
736
+ * older toggle can leave the list and the stack out of sync), reconcile it
737
+ * the same way the live toggle route does: remove the whole bundle so its
738
+ * entire patch stops applying on the next composition. Ordinary packages
739
+ * keep the best-effort entry disable they always had.
740
+ *
741
+ * The bundle removal edits the manifest for the NEXT composition; the
742
+ * current process already loaded the bundle, which is the same restart
743
+ * contract a live carrier toggle already has.
744
+ */
745
+ async function replayDisabledPackage(name) {
746
+ const carrierRows = carrierRowIds(activeProfileDir, name);
747
+ if (carrierRows.length > 0
748
+ && declaresBundle(activeProfileDir, name)
749
+ && readProfileBundles(activeProfileDir).includes(name)) {
750
+ removeProfileBundle(activeProfileDir, name);
751
+ logEvent('info', 'boot', `${name}: carrier removed from dsh.profile.bundles during boot replay (carrier rows: ${carrierRows.join(', ')}) — restart to finish; its gate is not disabled`);
752
+ return;
753
+ }
754
+ if (await themes.setEntryDisabled(name, true))
755
+ logEvent('info', 'boot', `plugin kept off: ${name}`);
756
+ }
725
757
  // Client-only packages (dsh.client without dsh.bundle) are invisible to the
726
758
  // bundle layer in every boot; the market shim-mounts them so their client
727
759
  // bundles are actually served.
@@ -736,8 +768,7 @@ export function mountMarketRoutes(host, config, commandRuntime, agentsLookup, ho
736
768
  if (followOutsideEnable(name))
737
769
  continue;
738
770
  noteHomeLayerConflict(name);
739
- if (await themes.setEntryDisabled(name, true))
740
- logEvent('info', 'boot', `plugin kept off: ${name}`);
771
+ await replayDisabledPackage(name);
741
772
  }
742
773
  });
743
774
  // Self-healing guard: dsh's own patch overlay can re-update entries during
@@ -746,8 +777,15 @@ export function mountMarketRoutes(host, config, commandRuntime, agentsLookup, ho
746
777
  host.on?.('internal/plugin', (payload) => {
747
778
  const fiber = payload;
748
779
  const name = fiber.entry?.options?.name;
749
- if (name !== undefined && disabled.has(name) && !followOutsideEnable(name))
750
- void themes.setEntryDisabled(name, true);
780
+ if (name === undefined || !disabled.has(name) || followOutsideEnable(name))
781
+ return;
782
+ // A carrier is reconciled by removing its bundle for the next
783
+ // composition, not by disabling its entries. Pushing a matching entry
784
+ // back down here would stop the gate foreign rows inject and re-strand
785
+ // them in the running process; let the restart finish the switch.
786
+ if (carrierRowIds(activeProfileDir, name).length > 0 && declaresBundle(activeProfileDir, name))
787
+ return;
788
+ void themes.setEntryDisabled(name, true);
751
789
  });
752
790
  let installing = false;
753
791
  let restarting = false;
@@ -928,6 +966,19 @@ export function mountMarketRoutes(host, config, commandRuntime, agentsLookup, ho
928
966
  if (listHotMounts().includes(name)) {
929
967
  ok = true;
930
968
  }
969
+ else if (carrierRowIds(dir, name).length > 0) {
970
+ // A carrier replaces something: its patch disables stock rows and its
971
+ // own rows stand in for them, with `disabled: !!js …` guards deciding
972
+ // which of the two is live on THIS host. Driving those rows up in the
973
+ // running process clears the guards and mounts the replacement beside
974
+ // the stock row — a second copy of a module the host already holds
975
+ // (`storage form 'domain' is already mounted`), which dsh answers by
976
+ // exiting (#1175). Enabling is the mirror of the disable branch below
977
+ // (#1010): the swap needs one composition, and a carrier switch is
978
+ // already reported as "restart to apply" — so nothing is gained by
979
+ // doing it live, and the host can die trying.
980
+ ok = true;
981
+ }
931
982
  else if (await themes.setEntryDisabled(name, false)) {
932
983
  ok = true;
933
984
  }
@@ -3165,12 +3216,22 @@ export function mountMarketRoutes(host, config, commandRuntime, agentsLookup, ho
3165
3216
  sendJson(response, 200, { compatibleVersion: null, reason: 'installed-version-unknown' });
3166
3217
  return;
3167
3218
  }
3168
- const compatibleVersion = await findCompatibleVersion(npmName, host.version, corePackageNames(host.directory ?? null), routesFor(region).npmRegistry, undefined, currentVersion);
3219
+ // The update route's own rule (#991): the Desktop moves a stable npm
3220
+ // install only to a stable release, so a prerelease found here would
3221
+ // be an enabled button that answers 409 (#1161).
3222
+ const stableOnly = upgradeOnly && config.desktopHost === true && !SELF_NAMES.has(npmName)
3223
+ && isStableReleaseVersion(currentVersion);
3224
+ const compatibleVersion = await findCompatibleVersion(npmName, host.version, corePackageNames(host.directory ?? null), routesFor(region).npmRegistry, undefined, currentVersion, stableOnly);
3169
3225
  // A compatible version is only advice until the release-age gate
3170
3226
  // agrees: the dialog says "update to X", and clicking that used to
3171
3227
  // dead-end on a 409 the log never mentioned. Answer both questions
3172
3228
  // here, where the caller can say "in about N hours" up front.
3173
- const maturity = compatibleVersion === null
3229
+ // An update on a CLI host has the one-shot release-age bypass (#39)
3230
+ // and installs a young release, the same reason checkUpdates holds
3231
+ // young releases on the Desktop only: there "held" would disable an
3232
+ // Update button that works.
3233
+ const ageGated = !upgradeOnly || config.desktopHost === true;
3234
+ const maturity = compatibleVersion === null || !ageGated
3174
3235
  ? null
3175
3236
  : await readVersionMaturity(npmName, compatibleVersion, config.profile, activeProfileDir);
3176
3237
  logEvent('info', 'find-compatible', `${npmName}: host=${host.version}, after=${currentVersion ?? 'none'} → ${compatibleVersion ?? 'none'}`
@@ -6081,6 +6142,25 @@ export function mountMarketRoutes(host, config, commandRuntime, agentsLookup, ho
6081
6142
  const ignoredBuilds = ok || cancelled || !failedOnBlockedBuilds(result) ? undefined : blockedBuilds(result);
6082
6143
  if (ok)
6083
6144
  clearBrokenPlugin(name);
6145
+ // #1093: the same leftover rows, on the update side. The old
6146
+ // version's `minimumReleaseAgeExclude` row outlives the update and
6147
+ // points at a build that is no longer on disk. Rows naming the
6148
+ // version that IS installed stay: a fresh release may need exactly
6149
+ // that row at the next install.
6150
+ if (ok && !restore) {
6151
+ try {
6152
+ const installedNow = readInstalledVersion(config.profile, name, activeProfileDir);
6153
+ if (installedNow !== null) {
6154
+ const staleExcludes = dropReleaseAgeExcludes(config.profile, name, activeProfileDir, installedNow);
6155
+ if (staleExcludes.length > 0) {
6156
+ logEvent('info', 'update', `${name}: dropped ${String(staleExcludes.length)} minimumReleaseAgeExclude row(s) for versions no longer installed`);
6157
+ }
6158
+ }
6159
+ }
6160
+ catch (error) {
6161
+ logEvent('warn', 'update', `${name}: could not clear old minimumReleaseAgeExclude rows — ${error instanceof Error ? error.message : String(error)}`);
6162
+ }
6163
+ }
6084
6164
  // A package still installed but no longer in dsh.profile.bundles
6085
6165
  // after this run stops loading and says nothing (#720). The market
6086
6166
  // does not write that list from anything but the current list, so
@@ -7314,6 +7394,8 @@ export function mountMarketRoutes(host, config, commandRuntime, agentsLookup, ho
7314
7394
  sendJson(response, 403, { error: 'untrusted origin' });
7315
7395
  return;
7316
7396
  }
7397
+ // Set once the package is on disk, so a failure after that point is not reported as a failed install.
7398
+ let installLanded = false;
7317
7399
  try {
7318
7400
  const body = (await readJsonBody(request));
7319
7401
  const drainCall = drainCallOf(request);
@@ -7712,6 +7794,7 @@ export function mountMarketRoutes(host, config, commandRuntime, agentsLookup, ho
7712
7794
  let compatibility;
7713
7795
  let addedPackages = [];
7714
7796
  if (ok) {
7797
+ installLanded = true;
7715
7798
  const added = Object.keys(installed).filter(name => !before.has(name));
7716
7799
  addedPackages = added;
7717
7800
  if (added.length > 0) {
@@ -7849,8 +7932,25 @@ export function mountMarketRoutes(host, config, commandRuntime, agentsLookup, ho
7849
7932
  }
7850
7933
  }
7851
7934
  }
7852
- if (ok)
7853
- clearBrokenPlugin(entry.name);
7935
+ // #1164: brokenPlugins is keyed by the PROFILE DEPENDENCY name —
7936
+ // the update path drops the declaration and records `name` there,
7937
+ // so the notice can be found by the package the user actually has.
7938
+ // A catalog entry is not that key: `entry.name` is the DISPLAY
7939
+ // name (the GitHub repo's casing, e.g. "DSH-better-sidebar") while
7940
+ // the package it installs is `entry.npm`. Clearing by the display
7941
+ // name was a silent no-op for every entry whose two differ, so the
7942
+ // spent notice outlived reloads, restarts and market upgrades
7943
+ // until the user dismissed it by hand. Clear by what this run
7944
+ // actually put into the profile, plus the entry's own package name
7945
+ // (a git-source entry has no `npm`, and `addedPackages` is empty
7946
+ // when the recovery path re-added a name the snapshot already had).
7947
+ if (ok) {
7948
+ const reinstalled = new Set(addedPackages);
7949
+ if (npmName !== null)
7950
+ reinstalled.add(npmName);
7951
+ for (const pkg of reinstalled)
7952
+ clearBrokenPlugin(pkg);
7953
+ }
7854
7954
  logEvent(ok || cancelled ? 'info' : 'error', 'install', `${target} exit=${String(result.exitCode)}${result.timedOut ? ' TIMEOUT' : ''}${cancelled ? ' CANCELLED' : ''}${ok ? ` hot=${String(hot)}` : cancelled ? '' : ` err=${failureDetail(result)}`}`);
7855
7955
  // On success a skipped build is a notice (#6); after a FAILURE the
7856
7956
  // list is what offers the approve-and-retry banner, so it is sent
@@ -7941,6 +8041,15 @@ export function mountMarketRoutes(host, config, commandRuntime, agentsLookup, ho
7941
8041
  if (!inProbe())
7942
8042
  host.logger?.warn(`[dsh-crate] install failed: ${message}`);
7943
8043
  logEvent('error', 'install', `route error: ${message}`);
8044
+ // A plugin that brings its own host half can make the host reload the
8045
+ // market while this request is still checking the result. The old
8046
+ // instance is gone, so what it throws now says nothing about the
8047
+ // install: the package landed, and the new instance reports the
8048
+ // real state of the plugin on the next refresh.
8049
+ if (installLanded && disposed) {
8050
+ sendJson(response, 200, { ok: true, hot: true, marketReloaded: true });
8051
+ return;
8052
+ }
7944
8053
  sendJson(response, 500, { error: message });
7945
8054
  }
7946
8055
  },
package/lib/themes.js CHANGED
@@ -12,7 +12,7 @@ import { logEvent } from './log.js';
12
12
  import { loaderEntryId } from './patch.js';
13
13
  import { LifecyclePendingError, LifecycleWaitError, waitForLifecycle } from './lifecycle.js';
14
14
  import { nameMatchesPackage } from './entry-identity.js';
15
- import { bundlePatchInsertedIds, profileDir, readInstalled } from './profile.js';
15
+ import { bundleExpressionRowIds, bundlePatchInsertedIds, profileDir, readInstalled } from './profile.js';
16
16
  import { parseSourceUrl, repoOfTarget } from './sources.js';
17
17
  /**
18
18
  * Whether an installed package declares itself a skin.
@@ -215,7 +215,24 @@ export function createThemeManager(host, profile, disabledThemes, explicitDir) {
215
215
  // looking for a naming bug (#619's shape) in a profile where the match
216
216
  // was fine and the runtime was simply still busy.
217
217
  let matched = false;
218
+ // Rows the package decides itself, by expression (`disabled: !!js …`),
219
+ // are not the market's to overrule (#1043). The durable layer already
220
+ // leaves them alone — `switchPluginLayers` filters them out through
221
+ // `bundleExpressionRowIds` — and the live layer has to agree: clearing a
222
+ // guard the host evaluated to `true` mounts the row anyway, which for a
223
+ // carrier means a second copy of a module the host already holds
224
+ // (`storage form 'domain' is already mounted`), and dsh answers a
225
+ // duplicate mount by exiting (#1175: dsh-tui on a web profile).
226
+ //
227
+ // Disabling still writes through: "off" cannot resurrect anything, and a
228
+ // guarded row the user wants off should stay off whichever way the
229
+ // condition falls.
230
+ const expressionIds = disabledFlag
231
+ ? null
232
+ : new Set(bundleExpressionRowIds(join(activeProfileDir, 'node_modules', name)));
218
233
  for (const entry of matchingEntries(name)) {
234
+ if (expressionIds !== null && expressionIds.has(entry.options.id ?? ''))
235
+ continue;
219
236
  matched = true;
220
237
  if (!disabledFlag && uncertainEntries.has(entry)) {
221
238
  throw new LifecycleWaitError('loader entry: runtime state is uncertain; retry disabling before enabling');
@@ -11,8 +11,8 @@
11
11
  export type HostCompatibilityStatus = 'compatible' | 'incompatible' | 'unknown';
12
12
  export type HostCompatibilityBasis = 'manifest' | 'undeclared' | 'unavailable';
13
13
  export interface HostRequirementDeclaration {
14
- kind: 'engine' | 'peer';
15
- /** Present only for a peer-derived declaration. */
14
+ kind: 'engine' | 'peer' | 'dependency';
15
+ /** Present only for a peer- or dependency-derived declaration. */
16
16
  package?: string;
17
17
  range: string;
18
18
  }
@@ -27,6 +27,12 @@ export interface NpmManifestFacts {
27
27
  version: string | null;
28
28
  enginesDsh: string | null;
29
29
  peerDependencies: Record<string, string>;
30
+ /**
31
+ * Ordinary dependencies that name a host package. Optional only because a
32
+ * durable cache entry or a catalog release manifest written before this
33
+ * field existed carries no value; a missing field declares nothing.
34
+ */
35
+ dependencies?: Record<string, string>;
30
36
  }
31
37
  type FetchLike = (url: string, init?: {
32
38
  signal?: AbortSignal;
@@ -138,8 +144,12 @@ export declare class DiscoveryManifestIndex {
138
144
  * installed one, which is what an update needs: suggesting a downgrade is not
139
145
  * an update.
140
146
  *
147
+ * `stableOnly` drops prereleases. The official Desktop refuses to move a
148
+ * stable install onto a prerelease by itself (#991), so offering one there is
149
+ * an enabled button that can only answer 409 (#1161).
150
+ *
141
151
  * @returns the version, or null when the packument cannot be read or nothing
142
152
  * in the history declares itself compatible.
143
153
  */
144
- export declare function findCompatibleVersion(npmName: string, hostVersion: string, hostPackages: ReadonlySet<string>, registry: string, fetcher?: FetchLike, minimumVersionExclusive?: string | null): Promise<string | null>;
154
+ export declare function findCompatibleVersion(npmName: string, hostVersion: string, hostPackages: ReadonlySet<string>, registry: string, fetcher?: FetchLike, minimumVersionExclusive?: string | null, stableOnly?: boolean): Promise<string | null>;
145
155
  export {};
@@ -385,7 +385,9 @@ export declare function hotMount(ctx: HotContext, profileDir: string, packageNam
385
385
  * in every boot — this is what makes them behave like normal plugins.
386
386
  * @returns names that were mounted.
387
387
  */
388
- export declare function mountClientOnlyDeps(ctx: HotContext, profileDir: string): Promise<string[]>;
388
+ export declare function mountClientOnlyDeps(ctx: HotContext, profileDir: string,
389
+ /** The host's install directory; `undefined` finds it, `null` means "do not look". */
390
+ hostDirectory?: string | null): Promise<string[]>;
389
391
  /**
390
392
  * Package names the profile's OWN bundle layer already mounts.
391
393
  *
@@ -401,7 +403,7 @@ export declare function mountClientOnlyDeps(ctx: HotContext, profileDir: string)
401
403
  * today's behaviour (shim, possibly duplicated) rather than silently dropping
402
404
  * a client bundle that the bundle layer never mounts.
403
405
  */
404
- export declare function bundleLayerTargets(profileDir: string, bundles: Iterable<string>): Set<string>;
406
+ export declare function bundleLayerTargets(profileDir: string, bundles: Iterable<string>, hostDirectory?: string | null): Set<string>;
405
407
  /**
406
408
  * Row ids and package names the user's own patch layer (cordis.patch.yml)
407
409
  * already contains. Line-wise scan on purpose: the file may hold structures
@@ -3,10 +3,27 @@
3
3
  * composes the webServer and shell services.
4
4
  */
5
5
  import type { Context } from '@deepseek-ai/cordis';
6
+ import z from '@deepseek-ai/schemastery';
6
7
  import { type MarketConfig } from './routes.ts';
7
8
  export declare const name = "dsh-crate";
8
9
  /** Optional cordis.yml configuration; profile defaults to `web`. */
9
10
  export type Config = Partial<Pick<MarketConfig, 'profile' | 'allowRestart' | 'maxSnapshots' | 'buildEnv'>>;
11
+ /** dsh 0.1.7+ builds its form from `plugin.Config` and writes `simplify(config)` back, so every field the market reads is named here or the first form save deletes it. Each is loose: an older composition still boots, a mistyped value is dropped, and neither editable field takes a default, so "unconfigured" stays distinguishable (#1144, #229). */
12
+ export declare const Config: z<Schemastery.ObjectS<{
13
+ profile: z<string, string>;
14
+ channel: z<string, string>;
15
+ region: z<string, string>;
16
+ allowRestart: z<boolean, boolean>;
17
+ maxSnapshots: z<number, number>;
18
+ buildEnv: z<import("@deepseek-ai/cosmokit").Dict<any, string>, import("@deepseek-ai/cosmokit").Dict<any, string>>;
19
+ }>, Schemastery.ObjectT<{
20
+ profile: z<string, string>;
21
+ channel: z<string, string>;
22
+ region: z<string, string>;
23
+ allowRestart: z<boolean, boolean>;
24
+ maxSnapshots: z<number, number>;
25
+ buildEnv: z<import("@deepseek-ai/cosmokit").Dict<any, string>, import("@deepseek-ai/cosmokit").Dict<any, string>>;
26
+ }>>;
10
27
  /**
11
28
  * The launcher's `profileContext` in one line, for the exported log (#744).
12
29
  *
@@ -18,12 +35,13 @@ export declare function describeProfileContext(value: unknown): string;
18
35
  /**
19
36
  * The deployment's declared authorities, read from the host (#729).
20
37
  *
21
- * DSH's own /api fence accepts loopback OR an authority the operator declared
22
- * (`dsh web --trusted-host <name>`, plus the LAN literals the CLI derives when
23
- * bound to 0.0.0.0). The market's routes are `exact` registrations on the bare
24
- * webServer, and exact matches win over that fence's prefix, so they never
25
- * pass through it — and a loopback-only rule of its own made every mutating
26
- * route 403 on any deployment reached by a name.
38
+ * DSH's own /api fence accepts loopback, the listener's bind IP literal, or an
39
+ * authority the operator declared (`dsh web --trusted-host <name>`). The
40
+ * market's routes are `exact` registrations on the bare webServer, and exact
41
+ * matches win over that fence's prefix, so they never pass through it — and a
42
+ * loopback-only rule of its own made every mutating route 403 on any deployment
43
+ * reached by a name. The source below therefore mirrors the host's fence: the
44
+ * declared `trustedHosts` plus the listener's own bind host from `webServer`.
27
45
  *
28
46
  * The `connection` service is optional: a host without it leaves the fence
29
47
  * exactly as it was, which is the behaviour every release so far has had.