dsh-crate 0.5.10 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/check.js CHANGED
@@ -902,7 +902,14 @@ export function buildBundleLayers(profileDirectory, bundleNames, specs, dshInsta
902
902
  // shadow, never evidence for the layer the running host loaded (#371).
903
903
  // Keep walking the profile anchor's parent search paths: Desktop heals an
904
904
  // authoritative host fallback at <profiles>/node_modules.
905
- const ignoredProfilePackage = dshInstallDir === null && hostProvided
905
+ //
906
+ // The same holds for ANY official-scope bundle while the installation is
907
+ // out of sight, not only the ones INBOX_BUNDLES names (#1281): pnpm lays
908
+ // `@deepseek-ai/dsh-mcp-client` into the profile as a community plugin's
909
+ // peer, and that npm copy carries no `dsh.bundle.patch`, because the one
910
+ // the host loads comes from the installation. Judging the copy declared
911
+ // the profile unbootable and rolled back every install and update.
912
+ const ignoredProfilePackage = dshInstallDir === null && (hostProvided || officialScope)
906
913
  ? join(profileDirectory, 'node_modules', name)
907
914
  : undefined;
908
915
  const anchors = [
package/lib/dsh-cli.js CHANGED
@@ -8,7 +8,7 @@
8
8
  */
9
9
  import { spawn, spawnSync } from 'node:child_process';
10
10
  import { existsSync, readFileSync, rmSync } from 'node:fs';
11
- import { homedir } from 'node:os';
11
+ import { homedir, tmpdir } from 'node:os';
12
12
  import { dirname, isAbsolute, join, resolve } from 'node:path';
13
13
  import { logEvent } from './log.js';
14
14
  import { createProgressTracker } from './ndjson.js';
@@ -749,6 +749,34 @@ export function probePnpm() {
749
749
  return probePnpmOnPath();
750
750
  return probeHostPackageManager().then(ready => ready ? true : probePnpmOnPath());
751
751
  }
752
+ /**
753
+ * The cwd to hand a provisioning child.
754
+ *
755
+ * `corepack enable`, `npm i -g` and `npm prefix -g` read no project files, so
756
+ * they gain nothing from inheriting this process's directory — and a host
757
+ * whose boot directory was deleted loses everything to it: the child dies
758
+ * inside `getcwd()` before running a line of its own logic, which is how a
759
+ * one-click setup ended up reporting `npm -g: exit=7` with `syscall:
760
+ * 'uv_cwd'` (#1270).
761
+ *
762
+ * A readable directory is still inherited unchanged, so a healthy machine
763
+ * behaves exactly as before, including the per-project `.npmrc` npm would
764
+ * read from it. Only an unreadable one is replaced, and then with a directory
765
+ * that exists by definition.
766
+ *
767
+ * `process.cwd()` throws instead of returning a stale path, so the call
768
+ * itself is the test.
769
+ * @returns `undefined` to inherit, or a directory that is known to exist.
770
+ */
771
+ export function provisionCwd() {
772
+ try {
773
+ process.cwd();
774
+ return undefined;
775
+ }
776
+ catch {
777
+ return tmpdir();
778
+ }
779
+ }
752
780
  /** Probe `pnpm --version` on PATH. */
753
781
  function probePnpmOnPath() {
754
782
  if (pnpmReady)
@@ -779,6 +807,7 @@ function runQuiet(file, args, timeoutMs) {
779
807
  env: spawnEnv(),
780
808
  stdio: ['ignore', 'pipe', 'pipe'],
781
809
  viaShell: winCmdShim,
810
+ cwd: provisionCwd(),
782
811
  });
783
812
  const output = createOutputBuffer(8 * 1024);
784
813
  const timer = setTimeout(() => killChild(child), timeoutMs);
@@ -894,11 +923,29 @@ function hostPackageManagerHint() {
894
923
  * @returns a bilingual, actionable hint, or undefined when unrecognized.
895
924
  */
896
925
  export function provisionHint(corepackOutput, npmOutput, npmFound = true, probeFailure = null) {
926
+ // npm started and then could not read the directory it was started in: the
927
+ // host's own cwd had been deleted, so `getcwd()` failed before npm reached
928
+ // any of its logic (#1270). Nothing is missing and nothing is
929
+ // misconfigured, which makes every PATH-shaped hint below — install pnpm,
930
+ // start from a terminal, set PNPM_HOME — advice for a problem this user
931
+ // does not have. `provisionCwd` now keeps a dead directory from being
932
+ // inherited in the first place, so reaching this means the cwd went away
933
+ // after the spawn; naming it is still the only accurate thing to say.
934
+ if (/syscall:\s*['"]uv_cwd['"]/.test(`${corepackOutput}\n${npmOutput}`)) {
935
+ return '这台机器上 dsh 进程启动时的工作目录已经被删掉了,所以 npm 还没跑到自己的逻辑就退了(`syscall: \'uv_cwd\'` 是取当前目录失败,不是找不到文件)。这不是 pnpm 的问题,也不是 PATH 的问题,装什么都修不好。请从一个存在的目录重启 dsh:launchd / systemd 托管的部署把工作目录指到一个确定存在的目录(例如 /tmp),或者先在终端 cd 到任意存在的目录再启动 / The directory this dsh process was started in no longer exists, so npm exited inside `getcwd()` before reaching any of its own logic (`syscall: \'uv_cwd\'` — reading the current directory failed, nothing is missing on disk). This is not a pnpm problem and not a PATH problem, and no install can fix it. Restart dsh from a directory that exists: for launchd/systemd deployments point the working directory at one that does (e.g. /tmp), or `cd` somewhere real before starting it';
936
+ }
897
937
  // Node itself unreachable: pointing the user back at this same button
898
938
  // would be a dead end (#32). `npmFound` answers this from disk, so it
899
939
  // holds on a Windows console that reports the same thing in a codepage we
900
- // cannot read (#167); the ENOENT match stays for callers without it.
901
- if (!npmFound || (/ENOENT/.test(corepackOutput) && /ENOENT/.test(npmOutput))) {
940
+ // cannot read (#167).
941
+ //
942
+ // The ENOENT pair stays as a fallback for callers that do not pass
943
+ // `npmFound`, but it now has to be a spawn-level miss — `spawn npm ENOENT`,
944
+ // the shape a command that was never found produces. Matching the bare
945
+ // word is how a genuine `spawn corepack ENOENT` got ANDed with npm's
946
+ // `uv_cwd` ENOENT: two unrelated meanings on one token (#1270).
947
+ const spawnMissed = (output, tool) => output.includes(`spawn ${tool} ENOENT`);
948
+ if (!npmFound || (spawnMissed(corepackOutput, 'corepack') && spawnMissed(npmOutput, 'npm'))) {
902
949
  // The searched list is spelled out because the previous wording named
903
950
  // only the Node directory, which was both incomplete and unhelpful: a
904
951
  // user who HAD installed pnpm could not tell whether we looked in the