Skip to content

Commit 80315ac

Browse files
wpfleger96npub1mn7jgtj4w2pd0g0zeuhxsa6jy6p0rewxz4kujt98my82ahfmp72sxjexk7
andauthored
fix(desktop): harden Windows installs against Defender block and orphaned Node (block#4382)
This PR fixes two Windows-specific install failures: Windows Defender blocking the bare `irm|iex` PowerShell install command, and managed Node shims pointing at a version-bumped (now-absent) Node directory. The Defender block (Trojan:Win32/Commando.A!ml) fires before PowerShell runs and is not clearable via Allow. The Node orphaning means shims in the managed npm prefix resolve but fail at runtime with 'node not recognized' because they reference the deleted old Node path. - Replace all three Windows CLI install commands (Goose, Claude, Codex) with a two-step shape — `Invoke-RestMethod` to a named temp file, then execute — to eliminate the dropper signature; a new `windows_install_command!` macro in `discovery/windows_install.rs` generates all three strings at compile time so the shape cannot drift between runtimes - `$ErrorActionPreference='Stop'` aborts on download failure instead of falling through to a missing-file exit-0; `exit $LASTEXITCODE` propagates the vendor script's own exit code - Add `probe_node(executable, expected_version, timeout)` as a bounded seam: stdout goes to a temp file (not a pipe) so no exit path can block on an inherited handle; the child runs in its own process group on Unix so an unconditional group SIGKILL on every exit path terminates all descendants; on Windows `taskkill /T /F` provides the same tree-wide cleanup; `managed_node_runtime_ready()` is a thin wrapper that resolves the managed Node path and calls the seam - Add `resolve_adapter_path()` in `managed_node.rs`: resolves the candidate first, then calls `should_invalidate_adapter()` — a pure predicate that returns `true` only when the resolved path is under `buzz_managed_npm_bin_dir()` AND the managed Node runtime is orphaned; external adapters outside the managed prefix are always preserved Note: CI cannot reproduce the Defender block (no live Defender ML classifier). Proof of fix is structural — the command shape no longer matches the dropper signature. Canary validation on a real Windows machine with Defender enabled is the definitive check. --------- Signed-off-by: Will Pfleger <[email protected]> Co-authored-by: npub1mn7jgtj4w2pd0g0zeuhxsa6jy6p0rewxz4kujt98my82ahfmp72sxjexk7 <dcfd242e557282d7a1e2cf2e6877522682f1e5c6156dc92ca7d90eaedd3b0f95@buzz.block.builderlab.xyz>
1 parent c1b88af commit 80315ac

5 files changed

Lines changed: 863 additions & 236 deletions

File tree

‎desktop/src-tauri/src/commands/agent_discovery.rs‎

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -333,10 +333,7 @@ fn install_acp_runtime_blocking(
333333
// For the codex runtime, "found" is not enough — the resolved binary must also
334334
// pass the 1.x version gate. An outdated 0.16.x adapter must be overwritten by
335335
// the new npm install so the CODEX_CONFIG spawn contract works correctly.
336-
let adapter_path = runtime
337-
.commands
338-
.iter()
339-
.find_map(|cmd| crate::managed_agents::resolve_command(cmd));
336+
let adapter_path = resolve_adapter_path(runtime.commands, runtime.adapter_install_commands);
340337
let adapter_probe_path = crate::managed_agents::readiness::cli_probe::augmented_path();
341338
if let Some(cmds) = plan_adapter_install(
342339
runtime_id,
@@ -1020,7 +1017,7 @@ use install_report::InstallReporter;
10201017
mod managed_node;
10211018
use managed_node::{
10221019
ensure_managed_node_runtime_blocking, managed_node_runtime_supported, managed_npm_command,
1023-
npm_eacces_hint,
1020+
npm_eacces_hint, resolve_adapter_path,
10241021
};
10251022

10261023
#[tauri::command]
@@ -1741,7 +1738,7 @@ mod tests {
17411738
#[test]
17421739
fn test_powershell_command_argv_exact() {
17431740
// Catalog format: body wrapped in one outer double-quote pair (Bash-layer serialization).
1744-
let body = "irm https://chatgpt.com/codex/install.ps1 | iex";
1741+
let body = "$ErrorActionPreference='Stop'; $installer=Join-Path $env:TEMP 'buzz-install-codex.ps1'; Invoke-RestMethod https://chatgpt.com/codex/install.ps1 -OutFile $installer; & $installer; exit $LASTEXITCODE";
17451742
let cmd = super::install_powershell_command(&format!(
17461743
r#"powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "{body}""#
17471744
));
@@ -1771,12 +1768,12 @@ mod tests {
17711768
);
17721769
}
17731770

1774-
/// Claude Code catalog command (discovery.rs:107) must dequote to the bare pipeline.
1771+
/// Claude Code catalog command must dequote to the two-step download-then-execute body.
17751772
#[cfg(windows)]
17761773
#[test]
17771774
fn test_powershell_command_claude_catalog_dequoted() {
17781775
let cmd = super::install_powershell_command(
1779-
r#"powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "irm https://claude.ai/install.ps1 | iex""#,
1776+
r#"powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "$ErrorActionPreference='Stop'; $installer=Join-Path $env:TEMP 'buzz-install-claude.ps1'; Invoke-RestMethod https://claude.ai/install.ps1 -OutFile $installer; & $installer; exit $LASTEXITCODE""#,
17801777
);
17811778
assert_eq!(
17821779
cmd.get_args()
@@ -1787,22 +1784,22 @@ mod tests {
17871784
"-ExecutionPolicy",
17881785
"Bypass",
17891786
"-Command",
1790-
"irm https://claude.ai/install.ps1 | iex",
1787+
"$ErrorActionPreference='Stop'; $installer=Join-Path $env:TEMP 'buzz-install-claude.ps1'; Invoke-RestMethod https://claude.ai/install.ps1 -OutFile $installer; & $installer; exit $LASTEXITCODE",
17911788
],
17921789
"Claude catalog command must be dequoted correctly"
17931790
);
17941791
}
17951792

1796-
/// Goose Windows catalog command (discovery.rs:78) must dequote to a bare pipeline
1797-
/// with a literal `$env:` prefix — no backslash before the dollar sign.
1798-
/// This proves the `\$` → `$` escape fix: post-#2750 the spawn is native and
1793+
/// Goose Windows catalog command must dequote to the two-step download-then-execute body
1794+
/// with the `$env:CONFIGURE` prefix intact — no backslash before the dollar sign.
1795+
/// This proves the `\$` → `$` contract: post-#2750 the spawn is native and
17991796
/// PowerShell receives the body verbatim, so a residual `\` would produce
18001797
/// `\$env:CONFIGURE='false'` which is a malformed statement.
18011798
#[cfg(windows)]
18021799
#[test]
18031800
fn test_powershell_command_goose_catalog_dequoted() {
18041801
let cmd = super::install_powershell_command(
1805-
r#"powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "$env:CONFIGURE='false'; irm https://raw.githubusercontent.com/aaif-goose/goose/main/download_cli.ps1 | iex""#,
1802+
r#"powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "$env:CONFIGURE='false'; $ErrorActionPreference='Stop'; $installer=Join-Path $env:TEMP 'buzz-install-goose.ps1'; Invoke-RestMethod https://raw.githubusercontent.com/aaif-goose/goose/main/download_cli.ps1 -OutFile $installer; & $installer; exit $LASTEXITCODE""#,
18061803
);
18071804
assert_eq!(
18081805
cmd.get_args()
@@ -1813,7 +1810,7 @@ mod tests {
18131810
"-ExecutionPolicy",
18141811
"Bypass",
18151812
"-Command",
1816-
"$env:CONFIGURE='false'; irm https://raw.githubusercontent.com/aaif-goose/goose/main/download_cli.ps1 | iex",
1813+
"$env:CONFIGURE='false'; $ErrorActionPreference='Stop'; $installer=Join-Path $env:TEMP 'buzz-install-goose.ps1'; Invoke-RestMethod https://raw.githubusercontent.com/aaif-goose/goose/main/download_cli.ps1 -OutFile $installer; & $installer; exit $LASTEXITCODE",
18171814
],
18181815
"Goose catalog command must dequote with bare $env: (no backslash before $)"
18191816
);

0 commit comments

Comments
 (0)