dsh-plugin-wsl-env 0.26.0 → 0.26.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/CHANGELOG.md +137 -0
  2. package/README.md +55 -158
  3. package/SUPPORT.md +2 -2
  4. package/SUPPORT.zh.md +2 -2
  5. package/docs/ARCHITECTURE.md +21 -5
  6. package/docs/ARCHITECTURE.zh.md +17 -4
  7. package/docs/CONFIGURATION.md +7 -9
  8. package/docs/CONFIGURATION.zh.md +6 -7
  9. package/docs/DIAGNOSTICS.md +21 -0
  10. package/docs/DIAGNOSTICS.zh.md +15 -0
  11. package/docs/LIMITATIONS.md +13 -1
  12. package/docs/LIMITATIONS.zh.md +12 -2
  13. package/docs/MIGRATION.md +4 -1
  14. package/docs/MIGRATION.zh.md +4 -1
  15. package/docs/PEER-PARITY.md +16 -0
  16. package/docs/QUICKSTART.md +22 -15
  17. package/docs/QUICKSTART.zh.md +19 -16
  18. package/docs/README.zh.md +59 -146
  19. package/docs/RELEASING.md +2 -2
  20. package/docs/REQUIREMENTS.zh.md +2 -2
  21. package/docs/ROADMAP-1.0.md +1 -1
  22. package/docs/VALUE.md +27 -0
  23. package/docs/VALUE.zh.md +27 -0
  24. package/docs/screenshots/with-plugin.png +0 -0
  25. package/docs/screenshots/with-plugin.svg +59 -0
  26. package/docs/screenshots/with-plugin.zh.png +0 -0
  27. package/docs/screenshots/with-plugin.zh.svg +56 -0
  28. package/docs/screenshots/without-plugin.png +0 -0
  29. package/docs/screenshots/without-plugin.svg +50 -0
  30. package/docs/screenshots/without-plugin.zh.png +0 -0
  31. package/docs/screenshots/without-plugin.zh.svg +45 -0
  32. package/lib/doctor-report.js +8 -1
  33. package/lib/git-exec.d.ts +39 -7
  34. package/lib/git-exec.js +151 -18
  35. package/lib/listing.d.ts +17 -0
  36. package/lib/listing.js +20 -0
  37. package/lib/messages.d.ts +27 -0
  38. package/lib/messages.js +26 -2
  39. package/lib/peer-versions.d.ts +53 -0
  40. package/lib/peer-versions.js +137 -0
  41. package/lib/picker.js +33 -19
  42. package/lib/search-exec.d.ts +45 -9
  43. package/lib/search-exec.js +152 -20
  44. package/lib/subprocess.d.ts +4 -1
  45. package/lib/subprocess.js +16 -3
  46. package/lib/update-check.d.ts +2 -2
  47. package/lib/update-check.js +2 -2
  48. package/lib/wsl-doctor-command.js +2 -1
  49. package/lib/wsl.d.ts +21 -0
  50. package/lib/wsl.js +24 -0
  51. package/package.json +9 -2
  52. package/scripts/doctor.mjs +148 -22
@@ -802,21 +802,113 @@ function comparePrerelease(left, right) {
802
802
  return 0;
803
803
  }
804
804
 
805
+ /** The private env contract: the peer set the spawning host process resolved. */
806
+ const HOST_PEERS_ENV = "DSH_WSL_DOCTOR_PEERS";
807
+
808
+ /** Per-directory peer declarations, read once per doctor run. */
809
+ const peerDeclarations = new Map();
810
+
811
+ /**
812
+ * The peer names one package project declares.
813
+ *
814
+ * The host's linked-plugin resolution applies a peer declaration at the first
815
+ * ancestor `node_modules` position whose project declares the name; the
816
+ * physical copy there is the one that position owns. A `node_modules`
817
+ * directory with no manifest above it (the stale tree a harness upgrade
818
+ * leaves behind) declares nothing and has no vote.
819
+ *
820
+ * @param {string} directory - the project directory that owns one `node_modules`.
821
+ * @returns {Set<string>} its declared peer names; empty when the manifest is absent.
822
+ */
823
+ function declaredPeers(directory) {
824
+ let peers = peerDeclarations.get(directory);
825
+ if (peers === undefined) {
826
+ try {
827
+ const manifest = /** @type {{ peerDependencies?: Record<string, string> }} */ (JSON.parse(readFileSync(join(directory, "package.json"), "utf8")));
828
+ peers = new Set(Object.keys(manifest.peerDependencies ?? {}));
829
+ } catch {
830
+ peers = new Set();
831
+ }
832
+ peerDeclarations.set(directory, peers);
833
+ }
834
+ return peers;
835
+ }
836
+
805
837
  /**
806
- * Read the installed version of one peer, or undefined when it cannot resolve.
838
+ * The directory of one peer as the plugin's own package tree carries it.
839
+ *
840
+ * Scoped to the first ancestor position that declares the peer. That mirrors
841
+ * the runtime's projection rule and keeps a copy from a `node_modules` above
842
+ * the plugin (an old installation tree, or a hoisted workspace) from being
843
+ * reported as the plugin's peer set. When the declaring position has no
844
+ * copy, the peer is not installed with the plugin — the standalone process
845
+ * cannot see whether the runtime projects an installation copy, so it reports
846
+ * that as unchecked rather than failed.
847
+ *
848
+ * @param {string} packageName - the peer package.
849
+ * @param {string} [root] - the plugin root; defaults to this script's root.
850
+ * @returns the package directory, or undefined when the plugin does not carry it.
851
+ */
852
+ export function peerPackageDir(packageName, root = ROOT) {
853
+ const require = createRequire(join(root, "package.json"));
854
+ for (const searchPath of require.resolve.paths(packageName) ?? []) {
855
+ if (!declaredPeers(dirname(searchPath)).has(packageName)) continue;
856
+ const candidate = join(searchPath, packageName);
857
+ return existsSync(join(candidate, "package.json")) ? candidate : undefined;
858
+ }
859
+ return undefined;
860
+ }
861
+
862
+ /**
863
+ * Read the installed version of one peer, or undefined when absent.
807
864
  * @param {string} packageName - the peer package.
808
865
  * @returns {string | undefined} the installed version.
809
866
  */
810
867
  function installedPeer(packageName) {
811
- const require = createRequire(join(ROOT, "package.json"));
868
+ const directory = peerPackageDir(packageName);
869
+ if (directory === undefined) return undefined;
812
870
  try {
813
- const manifest = /** @type {{ version?: string }} */ (JSON.parse(readFileSync(require.resolve(`${packageName}/package.json`), "utf8")));
871
+ const manifest = /** @type {{ version?: string }} */ (JSON.parse(readFileSync(join(directory, "package.json"), "utf8")));
814
872
  return manifest.version;
815
873
  } catch {
816
874
  return undefined;
817
875
  }
818
876
  }
819
877
 
878
+ /**
879
+ * The peer versions the spawning host process resolved, or undefined when
880
+ * this run is the standalone CLI.
881
+ *
882
+ * Presence of the variable is the signal: the in-app spawners always set it,
883
+ * even when the map is empty or partial, because a JSON object can only carry
884
+ * the peers that resolved. A missing peer then means "the host could not
885
+ * resolve it" and is reported unchecked — never looked up again in the
886
+ * plugin's physical tree, which may hold a stale copy from an older
887
+ * installation. A malformed value is treated as absent: it cannot come from
888
+ * {@link withHostPeerVersions}, so the standalone lookup is the honest
889
+ * fallback.
890
+ *
891
+ * @returns the name → version map, or undefined when the variable is absent
892
+ * or unparseable.
893
+ */
894
+ function hostPeerVersions() {
895
+ const raw = process.env[HOST_PEERS_ENV];
896
+ if (raw === undefined || raw.length === 0) return undefined;
897
+ let parsed;
898
+ try {
899
+ parsed = JSON.parse(raw);
900
+ } catch {
901
+ return undefined;
902
+ }
903
+ if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) return undefined;
904
+ /** @type {Record<string, string>} */
905
+ const versions = {};
906
+ for (const [name, version] of Object.entries(parsed)) {
907
+ if (typeof version === "string" && version.length > 0) versions[name] = version;
908
+ }
909
+ return versions;
910
+ }
911
+
820
912
  /**
821
913
  * The install remedy for one distro and family.
822
914
  * @param {string} distro - the distro name.
@@ -1417,23 +1509,31 @@ async function main(options) {
1417
1509
  }
1418
1510
 
1419
1511
  // ---- optional tools ------------------------------------------------------
1420
- // Feature-degradation warnings, not first-command prerequisites: the quick
1421
- // profile skips them (three process spawns a distro) and the full run names
1422
- // what each missing tool costs. None is a fallback-free break — a missing
1423
- // rg still leaves the model bash grep, a missing git still leaves
1424
- // file-tool edits, a missing inotifywait still polls.
1425
- if (!quick) {
1512
+ // Feature-degradation warnings, not first-command prerequisites. One
1513
+ // combined probe (one process a distro) runs them in the quick profile too,
1514
+ // so a missing rg is visible in the panel at startup instead of surfacing
1515
+ // as an opaque failure at the model's first grep/glob. None is a
1516
+ // fallback-free break — a missing rg still leaves bash grep, a missing git
1517
+ // still leaves file-tool edits, a missing inotifywait still polls.
1518
+ if (want("host")) {
1426
1519
  /** The optional tools, in the order users notice them losing. */
1427
1520
  /** @type {Array<[string, string]>} */
1428
- const optionalTools = [["rg", "the fs-search tool needs rg; the model can still run grep in a shell, slower"], ["git", "change review falls back to file-tool edits"], ["inotifywait", "the watcher falls back to polling"]];
1521
+ const optionalTools = [["rg", "the fs-search tool fails (exit 127); the model can still run grep in a shell, slower"], ["git", "change review falls back to file-tool edits"], ["inotifywait", "the watcher falls back to polling"]];
1522
+ // One `wsl.exe` for the set: every name is answered in the same shell, so
1523
+ // the quick profile pays one spawn, not three, for the full tool list.
1524
+ const toolAnswer = await probe(`for t in ${optionalTools.map(([tool]) => tool).join(" ")}; do if p=$(command -v "$t" 2>/dev/null); then printf 'found %s %s\\n' "$t" "$p"; else printf 'missing %s\\n' "$t"; fi; done`);
1525
+ /** @type {Map<string, string>} */
1526
+ const toolPaths = new Map();
1527
+ for (const line of toolAnswer.stdout.split(/\r?\n/)) {
1528
+ const match = /^(?:found|missing)\s+([a-z]+)(?:\s+(.*))?$/.exec(line.trim());
1529
+ if (match !== null && match[1] !== undefined) toolPaths.set(match[1], match[2] ?? "");
1530
+ }
1429
1531
  for (const [tool, cost] of optionalTools) {
1430
- const toolAnswer = await probe(`command -v ${tool}`);
1532
+ const found = toolPaths.get(tool);
1431
1533
  if (!toolAnswer.ok && toolAnswer.flaked) flakeCheck(`tools.${tool}`, tool, toolAnswer);
1432
- else {
1433
- const found = toolAnswer.stdout.trim();
1434
- if (found.length > 0) check(`tools.${tool}`, "ok", tool, found);
1435
- else check(`tools.${tool}`, "warn", tool, `missing; ${cost}`, install);
1436
- }
1534
+ else if (found === undefined) check(`tools.${tool}`, "info", tool, "the combined probe answered nothing for this tool, so this run cannot say whether it is installed");
1535
+ else if (found.length > 0) check(`tools.${tool}`, "ok", tool, found);
1536
+ else check(`tools.${tool}`, "warn", tool, `missing; ${cost}`, install);
1437
1537
  }
1438
1538
  }
1439
1539
 
@@ -1765,17 +1865,43 @@ async function main(options) {
1765
1865
  }
1766
1866
 
1767
1867
  // ---- peers ---------------------------------------------------------------
1868
+ // The host runtime projects a linked plugin's declared peers onto the
1869
+ // installation's single copies, so the spawning in-app process hands its
1870
+ // resolved set over. When that variable is present it is authoritative even
1871
+ // if partial or empty: a peer it omits could not be resolved by the host,
1872
+ // and falling back to this process's own lookup would report a stale copy
1873
+ // beside the plugin. Only the standalone CLI, with no variable at all,
1874
+ // looks in the plugin's tree; there, a peer nobody can see is unchecked
1875
+ // rather than failed, because the runtime may project an installation copy.
1768
1876
  const peers = Object.entries(manifest.peerDependencies ?? {});
1877
+ const hostPeers = hostPeerVersions();
1769
1878
  const badPeers = [];
1770
1879
  const unknownPeers = [];
1880
+ const uncheckedPeers = [];
1881
+ let matchedPeers = 0;
1771
1882
  for (const [name, range] of peers) {
1772
- const installed = installedPeer(name);
1773
- if (installed === undefined) badPeers.push(`${name}: not installed (want ${range})`);
1774
- else if (peerSatisfied(installed, range) === false) badPeers.push(`${name}: ${installed} (want ${range})`);
1775
- else if (peerSatisfied(installed, range) === undefined) unknownPeers.push(`${name}: ${installed} (range ${range} unchecked)`);
1883
+ const installed = hostPeers === undefined ? installedPeer(name) : hostPeers[name];
1884
+ if (installed === undefined) {
1885
+ uncheckedPeers.push(name);
1886
+ continue;
1887
+ }
1888
+ const satisfied = peerSatisfied(installed, range);
1889
+ if (satisfied === false) badPeers.push(`${name}: ${installed} (want ${range})`);
1890
+ else if (satisfied === undefined) unknownPeers.push(`${name}: ${installed} (range ${range} unchecked)`);
1891
+ else matchedPeers += 1;
1892
+ }
1893
+ if (badPeers.length === 0) {
1894
+ const hostNote = hostPeers === undefined ? "" : " (host runtime)";
1895
+ const unknownNote = unknownPeers.length > 0 ? `; ${unknownPeers.length} unrecognized range` : "";
1896
+ const uncheckedNote = uncheckedPeers.length > 0
1897
+ ? (hostPeers === undefined
1898
+ ? `; ${uncheckedPeers.length} not visible to this process (the runtime projects peers from the installation)`
1899
+ : `; ${uncheckedPeers.length} not resolved by the host runtime`)
1900
+ : "";
1901
+ check("peers.versions", "ok", "Peer versions", `${matchedPeers} pinned peer(s) match${hostNote}${unknownNote}${uncheckedNote}`);
1902
+ } else {
1903
+ check("peers.versions", "fail", "Peer versions", badPeers.join("; "), "install the peer set this plugin pins (pnpm install in the plugin, or reinstall/upgrade it against this harness); see docs/PEER-PARITY.md");
1776
1904
  }
1777
- if (badPeers.length === 0) check("peers.versions", "ok", "Peer versions", `${peers.length} pinned peer(s) match${unknownPeers.length > 0 ? `; ${unknownPeers.length} unchecked` : ""}`);
1778
- else check("peers.versions", "fail", "Peer versions", badPeers.join("; "), "install the peer set this plugin pins (pnpm install in the plugin, or reinstall/upgrade it against this harness); see docs/PEER-PARITY.md");
1779
1905
 
1780
1906
  phase("surveys");
1781
1907
  // ---- effective configuration (verdict inputs, reported) ------------------