Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins
TypeScript ai-agentcoding-agentdesktop-appelectronglobali18nlocal-firstmcppipi-agentpi-desktoppluginsreactrusttypescript
fix(host-core): detect MSIX Store pwsh app-execution aliases (#607) (#632)
Frank_zhu3173db521389
diff --git a/crates/host-core/Cargo.toml b/crates/host-core/Cargo.tomlindex d4c464124..78c938889 100644--- a/crates/host-core/Cargo.toml+++ b/crates/host-core/Cargo.toml@@ -35,6 +35,7 @@ tracing-subscriber = { version = "0.3", features = ["env-filter"] }windows-sys = { version = "0.61.2", features = ["Win32_Foundation","Win32_Globalization",+ "Win32_Storage_FileSystem","Win32_System_JobObjects","Win32_System_LibraryLoader","Win32_System_Registry",diff --git a/crates/host-core/src/tools/shell.rs b/crates/host-core/src/tools/shell.rsindex 9b60a250d..bafbd64cb 100644--- a/crates/host-core/src/tools/shell.rs+++ b/crates/host-core/src/tools/shell.rs@@ -571,10 +571,63 @@ fn is_executable(path: &Path) -> bool {#[cfg(windows)]fn is_executable(path: &Path) -> bool {- path.is_file()- && path- .extension()- .is_some_and(|extension| extension.eq_ignore_ascii_case(OsStr::new("exe")))+ if !path+ .extension()+ .is_some_and(|extension| extension.eq_ignore_ascii_case(OsStr::new("exe")))+ {+ return false;+ }+ windows_path_exists_as_non_directory(path)+}++/// Win32 `FILE_ATTRIBUTE_DIRECTORY`.+#[cfg(any(windows, test))]+const FILE_ATTRIBUTE_DIRECTORY: u32 = 0x0000_0010;++/// Decide whether a Windows `.exe` candidate exists from Win32 attributes.+///+/// `attributes` is `None` when `GetFileAttributesExW` failed (missing path,+/// typically `ERROR_PATH_NOT_FOUND` / `ERROR_FILE_NOT_FOUND`). Size is not an+/// input: Store app-execution aliases report size 0 and must still be accepted.+///+/// The reparse tag is optional because `GetFileAttributesExW` does not return+/// it. When present, `IO_REPARSE_TAG_APPEXECLINK` (0x8000001B) is accepted the+/// same as any other existing non-directory file.+#[cfg(any(windows, test))]+fn windows_exe_exists_from_win32_attrs(attributes: Option<u32>, _reparse_tag: Option<u32>) -> bool {+ let Some(attrs) = attributes else {+ return false;+ };+ if attrs & FILE_ATTRIBUTE_DIRECTORY != 0 {+ return false;+ }+ // Store aliases (`IO_REPARSE_TAG_APPEXECLINK`) and other non-directory+ // reparse points stay launchable via CreateProcessW even though CreateFileW+ // returns ERROR_CANT_ACCESS_FILE (1920). Do not require size > 0.+ true+}++/// `Path::is_file()` / `std::fs::metadata` use CreateFileW, which fails on+/// Microsoft Store app-execution aliases. `GetFileAttributesExW` succeeds on+/// those reparse points and still rejects a missing path.+#[cfg(windows)]+fn windows_path_exists_as_non_directory(path: &Path) -> bool {+ use std::os::windows::ffi::OsStrExt;+ use windows_sys::Win32::Storage::FileSystem::{+ GetFileAttributesExW, GetFileExInfoStandard, WIN32_FILE_ATTRIBUTE_DATA,+ };++ let mut wide: Vec<u16> = path.as_os_str().encode_wide().collect();+ wide.push(0);+ let mut info = WIN32_FILE_ATTRIBUTE_DATA::default();+ let ok = unsafe {+ GetFileAttributesExW(wide.as_ptr(), GetFileExInfoStandard, (&raw mut info).cast())+ };+ if ok == 0 {+ windows_exe_exists_from_win32_attrs(None, None)+ } else {+ windows_exe_exists_from_win32_attrs(Some(info.dwFileAttributes), None)+ }}#[cfg(test)]@@ -828,4 +881,46 @@ mod tests {);assert!(too_long.is_err());}++ // Win32 FILE_ATTRIBUTE_* / IO_REPARSE_TAG_* values used by the PATH+ // executable probe. These tests stay platform-agnostic so Linux CI covers+ // the Store alias decision that Path::is_file() gets wrong on Windows.+ const FILE_ATTRIBUTE_ARCHIVE: u32 = 0x0000_0020;+ const FILE_ATTRIBUTE_REPARSE_POINT: u32 = 0x0000_0400;+ const IO_REPARSE_TAG_APPEXECLINK: u32 = 0x8000_001B;++ #[test]+ fn windows_exe_attrs_accept_store_appexeclink_alias() {+ // Microsoft Store / MSIX app-execution aliases report ARCHIVE|REPARSE_POINT+ // and size 0. CreateFileW returns ERROR_CANT_ACCESS_FILE (1920), so+ // Path::is_file() / metadata reject them even though CreateProcessW+ // launches them. GetFileAttributesExW succeeds with these bits.+ let attrs = FILE_ATTRIBUTE_ARCHIVE | FILE_ATTRIBUTE_REPARSE_POINT;+ assert_eq!(attrs, 0x420);+ assert!(windows_exe_exists_from_win32_attrs(+ Some(attrs),+ Some(IO_REPARSE_TAG_APPEXECLINK),+ ));+ }++ #[test]+ fn windows_exe_attrs_reject_directory() {+ assert!(!windows_exe_exists_from_win32_attrs(+ Some(FILE_ATTRIBUTE_DIRECTORY),+ None,+ ));+ }++ #[test]+ fn windows_exe_attrs_reject_missing_path() {+ assert!(!windows_exe_exists_from_win32_attrs(None, None));+ }++ #[test]+ fn windows_exe_attrs_accept_normal_file() {+ assert!(windows_exe_exists_from_win32_attrs(+ Some(FILE_ATTRIBUTE_ARCHIVE),+ None,+ ));+ }}diff --git a/docs/spec/03-runtime/03-tools-and-permissions.md b/docs/spec/03-runtime/03-tools-and-permissions.mdindex 489d37915..2af8ccf0e 100644--- a/docs/spec/03-runtime/03-tools-and-permissions.md+++ b/docs/spec/03-runtime/03-tools-and-permissions.md@@ -368,10 +368,14 @@ or executable path hash is accepted as shell identity.- Windows PowerShell and cmd use their native non-interactive invocation.- PowerShell 7 resolves `pwsh.exe` from `%ProgramFiles%\PowerShell\7` (or`ProgramW6432` when the host process is 32-bit), then PATH, which covers- machine-scope, Store, user-scope, and portable installs. It shares the- Windows PowerShell 5.1 invocation contract and is never selected implicitly,- so it cannot change an existing user's default shell. Resolution failure- returns `SHELL_NOT_FOUND` naming the locations that were searched.+ machine-scope, Store, user-scope, and portable installs. The PATH probe+ treats Microsoft Store / MSIX app-execution aliases under `WindowsApps`+ (`IO_REPARSE_TAG_APPEXECLINK`) as present executables, because winget's+ default PowerShell 7 layout is an `msixbundle` that does not create+ `%ProgramFiles%\PowerShell\7`. It shares the Windows PowerShell 5.1+ invocation contract and is never selected implicitly, so it cannot change an+ existing user's default shell. Resolution failure returns `SHELL_NOT_FOUND`+ naming the locations that were searched.- Git Bash uses the discovered Git for Windows executable.- Unix Bash uses an approved system Bash entry.- User abort and timeout terminate the complete process tree before returning.diff --git a/docs/spec/06-delivery/04-e2e-test-plan.md b/docs/spec/06-delivery/04-e2e-test-plan.mdindex 34e981a06..c8de1b71d 100644--- a/docs/spec/06-delivery/04-e2e-test-plan.md+++ b/docs/spec/06-delivery/04-e2e-test-plan.md@@ -5789,6 +5789,25 @@ identify the platform validation still needed.validation, persistence, and restart; the deterministic host-core catalogtest verifies first-available fallback when a stored shell becomes unavailable+#### E2E-SHELL-windows-pwsh-msix-store-alias-is-available++- **Preconditions**: Windows host with PowerShell 7 installed via MSIX /+ Microsoft Store (`winget` `msixbundle`). `%ProgramFiles%\PowerShell\7\pwsh.exe`+ is absent. `pwsh.exe` on PATH is the `WindowsApps` app-execution alias+ (`IO_REPARSE_TAG_APPEXECLINK`).+- **Steps**: 1) Open Settings → command shell. 2) Inspect `windows-pwsh`+ availability. 3) Select PowerShell 7 and persist `defaultCommandShell`.+ 4) Run `Bash`.+- **Expected**: `windows-pwsh` is available and selectable. The host resolves+ the Store alias without treating it as missing. `Bash` launches PowerShell 7.+- **Specs linked**: `03-runtime/03-tools-and-permissions.md`,+ `04-ux/06-settings-ia.md`, ADR 0054, ADR 0209+- **Acceptance**: B (model/config), E (tools/permissions)+- **Milestone**: M6+- **Status**: Documented; host-core unit tests cover the Win32-attribute+ decision (alias attrs `0x420` + tag `0x8000001B`). Live Store-alias probe is+ Windows-only and is not run in Linux CI.+#### E2E-113: Stale shell identity fails closed- **Preconditions**: A Bash turn has a pinned effective shell ID/dialect; the