Skip to content

🤖 Open-source, local-first alternative to Grok Bot, OpenAI dots and Claude Duet. Your own AI bots on any model: GPT, Claude, Gemini, Grok, DeepSeek, Kimi, GLM and 70+ more through one Modelflare key. Reach them in the app, WeChat or Feishu; they remember you, work in the background, run commands and use your computer. Pay per use.

fix(windows): read the Win32 code from DSH's one-line sandbox error

Marlad14479b44697
diff --git a/src/agent/pwsh.ts b/src/agent/pwsh.ts
index f10ef2f..8269130 100644
--- a/src/agent/pwsh.ts
+++ b/src/agent/pwsh.ts
@@ -187,9 +187,12 @@ export function shellStartFailure(text: string, exe: string): string | undefined
for (const line of text.split(/\r?\n/)) {
const l = norm(line);
if (!l.includes(want)) continue;
+ // DSH 把整段沙箱错误写在一行里(几百个字),返回从 runner / spawn 的那句开始的部分
+ const from = (i: number) => line.slice(Math.max(0, i)).trim().slice(0, 300);
const acl = /windows-acl-run:.*createprocess\w*\s+failed\s+\(win32\s+(\d+)\)/.exec(l);
- if (acl && EXE_WIN32_CODES.has(Number(acl[1]))) return line.trim().slice(0, 300);
- if (/failed before reporting an outcome/.test(l) || /\bspawn\s.*\b(enoent|eacces|eperm|unknown|einval)\b/.test(l)) return line.trim().slice(0, 300);
+ if (acl && EXE_WIN32_CODES.has(Number(acl[1]))) return from(acl.index);
+ const spawn = /failed before reporting an outcome|\bspawn\s.*\b(enoent|eacces|eperm|unknown|einval)\b/.exec(l);
+ if (spawn) return from(spawn.index);
}
return undefined;
}
@@ -611,7 +614,7 @@ export function pwshStatusLine(st: PwshStatus): string {
const fb = st.fallback ? `;之前用的 ${st.fallback.from} 起不来(${st.fallback.reason.slice(0, 120)}),已自动换掉` : "";
if (!st.missing) return `PowerShell:${st.version ?? "7"}(${st.source === "private" ? "应用内置," : ""}代理用它执行命令)${fb}`;
const p = st.private;
- if (p && isInstalling(p.install)) return `PowerShell:正在为代理安装 PowerShell 7…(${installProgressText(p.install)})。装好之前命令照常用 Windows PowerShell 5.1`;
+ if (p && isInstalling(p.install)) return `PowerShell:正在为代理安装 PowerShell 7…${installProgressText(p.install)}。装好之前命令照常用 Windows PowerShell 5.1`;
if (p?.bad && st.mode !== "system") return `PowerShell:应用内置的 PowerShell 7 用不了(${p.bad.reason.slice(0, 160)}),${SLOW}。在 设置 → 故障排查 里可以一键重新安装`;
if (p?.install.state === "failed" && st.mode !== "system") return `PowerShell:为代理安装 PowerShell 7 没有成功(${p.install.error ?? "未知原因"}),${SLOW}。在 设置 → 故障排查 里可以重试,或者自己安装:${PWSH_WINGET}`;
if (p && !p.supported && p.reason) return `PowerShell:${p.reason},${SLOW}`;
diff --git a/test/pwsh-private.unit.test.ts b/test/pwsh-private.unit.test.ts
index dc3c0e7..24cb2ba 100644
--- a/test/pwsh-private.unit.test.ts
+++ b/test/pwsh-private.unit.test.ts
@@ -429,9 +429,9 @@ describe("探测器:优先级、自动安装、自动退回", () => {
probe.observeToolResult(exe, "Get-Foo: The term 'Get-Foo' is not recognized as a name of a cmdlet\n[exit code: 1]");
probe.observeToolResult(exe, `windows-acl-run: CreateProcessAsUserW failed (Win32 2): command: C:\\other\\pwsh.exe, cwd: C:\\ws`);
expect(probe.cachedDshPath).toBe(exe);
- // 沙箱 runner 拉不起它
- const text = `sandbox mode "workspace-write" is requested but no sandbox backend is usable on this host; refusing to run the command unconfined. Runner failure: windows-acl-run: CreateProcessAsUserW failed (Win32 2): command: ${exe}, cwd: C:\\data\\workspaces\\default`;
- expect(shellStartFailure(text, exe)).toContain("CreateProcessAsUserW failed (Win32 2)");
+ // 沙箱 runner 拉不起它(Windows CI 上的原文:整段在一行里,几百个字)
+ const text = `Error: sandbox mode "workspace-write" is requested but no sandbox backend is usable on this host; refusing to run the command unconfined. Install bubblewrap or run a Landlock-enforcing kernel (Linux), ensure sandbox-exec is usable (macOS), or ensure the ACL restricted-token runner can start (Windows) — otherwise switch the consumer to danger-full-access. Runner failure: windows-acl-run: CreateProcessAsUserW failed (Win32 2): command: ${exe}, cwd: D:\\a\\_temp\\e2e-private-pwsh\\data\\workspaces\\default`;
+ expect(shellStartFailure(text, exe)).toMatch(/^windows-acl-run: CreateProcessAsUserW failed \(Win32 2\): command: /);
probe.observeToolResult(exe, text);
const st = probe.snapshot();
expect(st).toMatchObject({ missing: true, using: PS5, private: { ready: false, bad: { reason: "代理拉不起它:找不到 pwsh.exe(可能被杀毒软件删除或隔离)(Win32 2)" } }, fallback: { from: exe, to: PS5 } });