dsh-composer-ux 0.6.1 → 0.6.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.
package/lib/index.js CHANGED
@@ -1086,6 +1086,9 @@ function terminalStatusText(input) {
1086
1086
  if (input.mode === "pwsh") {
1087
1087
  return "\u4FDD\u6301 DSH \u9ED8\u8BA4\uFF08PowerShell\uFF09\u2014\u2014\u672C\u63D2\u4EF6\u4E0D\u4ECB\u5165\u7EC8\u7AEF\u5DE5\u5177\u9762";
1088
1088
  }
1089
+ if (input.probeFailed !== void 0 && input.probeFailed !== "") {
1090
+ return `\u5DF2\u542F\u7528\uFF0C\u4F46\u81EA\u68C0\u672A\u901A\u8FC7\uFF1A${input.probeFailed} \u2014\u2014 \u4E3A\u907F\u514D\u628A\u4F1A\u8BDD\u7684 shell \u6253\u6B7B\uFF0C\u6682\u4E0D\u63A5\u7BA1\uFF08\u4FDD\u6301 PowerShell\uFF09`;
1091
+ }
1089
1092
  if (input.effective === "bash") {
1090
1093
  const path = input.effectivePath ?? "";
1091
1094
  const candidate = input.candidates.find((item) => item.path === path);
@@ -1603,6 +1606,7 @@ function createBashTool(deps, options) {
1603
1606
  const escalationModes = escalationModesOf(deps);
1604
1607
  const sep2 = options.sep ?? "\\";
1605
1608
  const isAbsolute2 = options.isAbsolute ?? ((path) => /^([a-zA-Z]:[\\/]|[\\/])/.test(path));
1609
+ const electron = options.electron ?? process.versions.electron !== void 0;
1606
1610
  const minTimeout = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
1607
1611
  const maxTimeout = options.maxTimeoutMs ?? MAX_TIMEOUT_MS;
1608
1612
  const spawnSpec = (argv, cwd, dshEnv, signal) => ({
@@ -1616,7 +1620,17 @@ function createBashTool(deps, options) {
1616
1620
  graceMs: GRACE_MS,
1617
1621
  ...signal === void 0 ? {} : { signal },
1618
1622
  // dshEnv 必须显式带上:subprocess 会先按凭据形状清洗父环境(含清掉所有 DSH_*)。
1619
- env: { ...ENV_OVERRIDES, ...dshEnv }
1623
+ env: {
1624
+ ...ENV_OVERRIDES,
1625
+ ...dshEnv,
1626
+ // ⚠️ 打包形态(Electron 桌面版)下必须补这一项。Windows 上受限模式的沙箱 runner
1627
+ // 的 argv[0] 是 `process.execPath`(`dsh-sandbox-local/lib/index.js:539`),桌面版里
1628
+ // 那就是 `DeepSeek Harness.exe`;而用 Electron 跑 JS 脚本**必须**带
1629
+ // `ELECTRON_RUN_AS_NODE=1`,否则它按 App 形态启动、原生初始化就失败
1630
+ // (2026-09-25 实测:零输出 / 0xC0000142)。官方 `sandbox-local` 只返回 argv、不带 env,
1631
+ // 所以这一项只能由 **spawn 方**补齐。对 `bash.exe` 本身无副作用(它不认这个变量)。
1632
+ ...electron ? { ELECTRON_RUN_AS_NODE: "1" } : {}
1633
+ }
1620
1634
  });
1621
1635
  const readFrame = (handle, offsets) => {
1622
1636
  const outRead = handle.collected.stdout?.readFrom(offsets.stdout);
@@ -1810,6 +1824,52 @@ ${raw.replace(/\n+$/, "")}
1810
1824
  }
1811
1825
  };
1812
1826
  }
1827
+ var PROBE_COMMAND = "printf %s dsh-composer-ux-probe-ok";
1828
+ var PROBE_MARKER = "dsh-composer-ux-probe-ok";
1829
+ var PROBE_TIMEOUT_MS = 8e3;
1830
+ function formatProbeExit(exitCode) {
1831
+ if (exitCode === null) return "null\uFF08\u88AB\u4FE1\u53F7\u7ED3\u675F\uFF09";
1832
+ if (exitCode < 0 || exitCode >= 2147483648) {
1833
+ const unsigned = exitCode < 0 ? exitCode + 4294967296 : exitCode;
1834
+ return `0x${unsigned.toString(16).toUpperCase()}\uFF08${unsigned}\uFF09`;
1835
+ }
1836
+ return String(exitCode);
1837
+ }
1838
+ async function probeBashExecution(deps, options, exec) {
1839
+ const probeDeps = deps.shellEnv === void 0 ? deps : {
1840
+ ...deps,
1841
+ shellEnv: {
1842
+ collect: (ctx) => {
1843
+ try {
1844
+ return deps.shellEnv?.collect(ctx) ?? {};
1845
+ } catch {
1846
+ return {};
1847
+ }
1848
+ }
1849
+ }
1850
+ };
1851
+ try {
1852
+ const tool = createBashTool(probeDeps, { ...options, timeoutMs: PROBE_TIMEOUT_MS, maxTimeoutMs: PROBE_TIMEOUT_MS });
1853
+ const result = await tool.execute(
1854
+ { command: PROBE_COMMAND, description: "composer-ux terminal self-check", timeoutMs: PROBE_TIMEOUT_MS },
1855
+ exec
1856
+ );
1857
+ if (result?.kind !== "foreground") return { ok: false, detail: "\u81EA\u68C0\u6CA1\u6709\u8D70\u524D\u53F0\u6267\u884C\u8DEF\u5F84" };
1858
+ if (result.timedOut === true) return { ok: false, detail: `\u81EA\u68C0\u8D85\u65F6\uFF08${PROBE_TIMEOUT_MS}ms\uFF09` };
1859
+ const text = result.stdout?.text ?? "";
1860
+ const exit = result.exitCode ?? 0;
1861
+ if (exit !== 0) {
1862
+ return {
1863
+ ok: false,
1864
+ detail: `\u81EA\u68C0\u547D\u4EE4\u9000\u51FA\u7801 ${formatProbeExit(exit)}${text.trim() === "" ? "\uFF08\u96F6\u8F93\u51FA\uFF09" : ""}`
1865
+ };
1866
+ }
1867
+ if (!text.includes(PROBE_MARKER)) return { ok: false, detail: "\u81EA\u68C0\u6CA1\u62FF\u5230\u9884\u671F\u8F93\u51FA\uFF08\u547D\u4EE4\u6CA1\u771F\u6B63\u8DD1\u8D77\u6765\uFF09" };
1868
+ return { ok: true, detail: "" };
1869
+ } catch (error) {
1870
+ return { ok: false, detail: error instanceof Error ? error.message : String(error) };
1871
+ }
1872
+ }
1813
1873
 
1814
1874
  // src/terminal/host.ts
1815
1875
  var TERMINAL_OFF_TEXT = "\u672A\u542F\u7528\uFF1A\u6253\u5F00\u8FD9\u4E00\u680F\u7684\u5F00\u5173\u540E\u624D\u4F1A\u63A5\u7BA1\uFF08\u73B0\u5728\u4FDD\u6301 PowerShell\uFF09";
@@ -1834,6 +1894,8 @@ function installTerminalPolicy(ctx, namespace, settings, readToolDeps, options =
1834
1894
  let lastDeliveryFailure = "";
1835
1895
  let busy = false;
1836
1896
  let again = false;
1897
+ let probeKey = "";
1898
+ let probeOutcome;
1837
1899
  const discover = options.discover ?? ((explicitPath) => probeBash(
1838
1900
  explicitPath,
1839
1901
  process.env.PATH ?? "",
@@ -1917,6 +1979,41 @@ function installTerminalPolicy(ctx, namespace, settings, readToolDeps, options =
1917
1979
  ...skips.length === 0 ? {} : { skipped: skips.join("\uFF1B") }
1918
1980
  };
1919
1981
  };
1982
+ const confinedModeOf = (deps, agent) => {
1983
+ if (deps?.sandbox === void 0 || deps.sandboxPolicy === void 0) return "";
1984
+ try {
1985
+ const session = agent?.session;
1986
+ const mode = deps.sandboxPolicy.resolve(session === void 0 ? {} : { session }).mode;
1987
+ return mode === "read-only" || mode === "workspace-write" ? mode : "";
1988
+ } catch {
1989
+ return "";
1990
+ }
1991
+ };
1992
+ const runProbe = async (deps, bashPath, mode, agent) => {
1993
+ const key = `${bashPath}|${mode}`;
1994
+ if (probeOutcome !== void 0 && probeKey === key) return probeOutcome;
1995
+ const controller = new AbortController();
1996
+ const timer = setTimeout(() => {
1997
+ controller.abort();
1998
+ }, PROBE_TIMEOUT_MS * 2);
1999
+ try {
2000
+ probeOutcome = await (options.probe ?? probeBashExecution)(
2001
+ deps,
2002
+ { bashPath, sep, isAbsolute },
2003
+ {
2004
+ callId: "composer-ux-self-check",
2005
+ signal: controller.signal,
2006
+ ...agent === void 0 ? {} : { agent }
2007
+ }
2008
+ );
2009
+ } catch (error) {
2010
+ probeOutcome = { ok: false, detail: error instanceof Error ? error.message : String(error) };
2011
+ } finally {
2012
+ clearTimeout(timer);
2013
+ }
2014
+ probeKey = key;
2015
+ return probeOutcome;
2016
+ };
1920
2017
  const reconcile = () => {
1921
2018
  if (busy) {
1922
2019
  again = true;
@@ -1954,9 +2051,24 @@ function installTerminalPolicy(ctx, namespace, settings, readToolDeps, options =
1954
2051
  const candidates = candidatesToStored(found.candidates);
1955
2052
  const bashPath = activeBashPath(mode, explicit, candidates, found.explicit);
1956
2053
  const usable = bashPath !== "" && existsFn(bashPath);
2054
+ let probeFailure = "";
1957
2055
  if (usable) {
2056
+ const probeDeps = readToolDeps();
1958
2057
  lastDeliveryFailure = "";
1959
2058
  for (const agent of agents?.list() ?? []) {
2059
+ const confinedMode = probeDeps === void 0 ? "" : confinedModeOf(probeDeps, agent);
2060
+ if (confinedMode !== "") {
2061
+ const probe = await runProbe(probeDeps, bashPath, confinedMode, agent);
2062
+ if (!probe.ok) {
2063
+ probeFailure = `${probe.detail}\uFF1B\u53D7\u9650\u6A21\u5F0F ${confinedMode}`;
2064
+ const current2 = installed.get(agent);
2065
+ if (current2 !== void 0) {
2066
+ current2.dispose();
2067
+ installed.delete(agent);
2068
+ }
2069
+ continue;
2070
+ }
2071
+ }
1960
2072
  const current = installed.get(agent);
1961
2073
  if (current !== void 0 && current.path === bashPath) continue;
1962
2074
  if (current !== void 0) {
@@ -1966,6 +2078,7 @@ function installTerminalPolicy(ctx, namespace, settings, readToolDeps, options =
1966
2078
  const record = install(agent, bashPath);
1967
2079
  if (record !== void 0) installed.set(agent, record);
1968
2080
  }
2081
+ if (probeFailure !== "") lastDeliveryFailure = probeFailure;
1969
2082
  } else {
1970
2083
  for (const entry of installed.values()) entry.dispose();
1971
2084
  installed.clear();
@@ -1983,7 +2096,9 @@ function installTerminalPolicy(ctx, namespace, settings, readToolDeps, options =
1983
2096
  ...found.explicit === void 0 ? {} : { explicit: found.explicit },
1984
2097
  effective: delivered ? "bash" : "pwsh",
1985
2098
  ...delivered ? { effectivePath: bashPath } : {},
1986
- ...delivered ? {} : { deliveryFailed: true },
2099
+ // 自检没过时优先用那条更准确的说法("预检就没过、根本没试"),
2100
+ // 而不是泛泛的"找到了 bash 但没能换上"。
2101
+ ...delivered ? {} : probeFailure === "" ? { deliveryFailed: true } : { probeFailed: probeFailure },
1987
2102
  ...failureText === "" ? {} : { failure: failureText }
1988
2103
  }),
1989
2104
  effective: delivered ? "bash" : "pwsh",