Skip to content

Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.

fix(desktop): the app becomes findable — the launcher leaves the Store Python's container

Haraldbd41e3d8b344
diff --git a/docs/BUGS.md b/docs/BUGS.md
index cf7e191cad..ffa0056dc7 100644
--- a/docs/BUGS.md
+++ b/docs/BUGS.md
@@ -9559,3 +9559,94 @@ the fixed-budget form, losing the final fragment exactly as the live call did;
`test_a_loud_but_wordless_floor_still_releases_the_order` for the bounded
half) and `tests/unit/realtime/test_gemini_live.py` (default sensitivity, the
opt-out, and the old-SDK degradation).
+
+---
+
+## BUG-138: the app is absent from Windows Search — the Start-Menu launcher is written into the Store Python's MSIX container, and every check reads it back from there (HIGH, FIXED 2026-08-16)
+
+**Symptom.** Typing the product name into Windows Search returned a folder as
+the best match and no application. The app could only be started from its
+Desktop icon. On macOS and Linux the equivalent entry existed on disk but did
+not appear in the desktop's app search until the next login.
+
+**Root.** A Python installed from the Microsoft Store runs inside an MSIX
+package container, and a virtual environment built from it inherits that
+identity — `sys.executable` points at the venv's own `Scripts\python.exe`, so
+nothing in the process looks packaged. Windows redirects such a process's
+writes to `%APPDATA%` and `%LOCALAPPDATA%` into a private per-package tree
+under `%LOCALAPPDATA%\Packages\<family>\LocalCache`. The per-user Start Menu
+lives in `%APPDATA%`. So every launcher this code "wrote into the Start Menu"
+was diverted into the container, where no shell ever looks. The folder the
+shell reads was empty the whole time.
+
+The Desktop kept working because the Desktop is not one of the redirected
+roots — which is exactly why the report read "only the Desktop icon starts
+it", and why the previous fix (adding a Desktop launcher) appeared to help
+while leaving the real defect untouched.
+
+**Why it survived three attempts.** The redirection is invisible from the
+inside: reads are redirected too. `lnk.is_file()` answered `True` for the
+trapped copy, `_shortcut_matches_install` happily validated its target and
+icon, and `ensure_start_menu_shortcut` returned `True`. Every layer reported
+success against a file only it could see. An earlier session measured the
+shell's app index straight after writing, found the entry missing, wrote a
+plain `notepad.exe` shortcut as a control, saw that missing too, and concluded
+the machine's app index was broken. The control was written by the same
+packaged interpreter and landed in the same container — it proved the opposite
+of what it appeared to prove.
+
+**Second half: the file has to be somewhere the index reads.** Once the
+launcher reached the real per-user Start Menu, the content index still did not
+carry it: on this machine the index holds only the ALL-USERS Start Menu
+(`%ProgramData%`), which is where Chrome — the app the report used as the
+benchmark — installs itself. A per-user install is reachable through the app
+resolver rather than the file index, which is why the entry had to be a real
+app entry (own executable as the target, AUMID attached) and not merely a file
+in the right folder.
+
+**Fix.** `jarvis/ui/msix_redirection.py`, wired into the launcher lifecycle:
+
+- Detect package identity with `GetCurrentPackageFamilyName` — the only
+ trustworthy probe, since the interpreter path shows nothing.
+- Publish the trapped launcher into the real tree through a helper process
+ that has no package identity (`powershell.exe` from System32). Its exit code
+ is an honest answer to "does the shell see this file?", because the check
+ runs outside the container. A launcher that stays trapped is now reported as
+ NOT installed instead of as a success.
+- Drop the container copy afterwards, so MSIX's container-first read
+ resolution falls through to the real path and every later `is_file()` /
+ staleness check upstream reasons about what the shell sees.
+- Uninstall goes the same way: deletion is redirected exactly like writing, so
+ an uninstall used to remove only its own container copy and leave a working
+ launcher for a deleted install.
+
+Helper paths travel in the environment, never on the command line, so a path
+holding a space or a quote cannot become script.
+
+OS parity, same class of defect — the file was written and never announced:
+Linux now calls `update-desktop-database` (and carries `Keywords=`, since app
+search matches `Name=` and a two-word product name loses the half users type),
+macOS registers the bundle with `lsregister`. Both degrade honestly to
+"appears after the next login" when the tool is absent.
+
+**Class.** A success reported against a read that goes through the same lie as
+the write. Any check that verifies an external artifact from inside the process
+that produced it can only confirm its own intent. Where an artifact exists for
+ANOTHER program to find — a shell, an index, a package manager — the
+verification has to come from that side, or it is not a verification. The
+generalisation is not MSIX-specific: sandboxes, overlay mounts, and per-user
+virtual stores all fail this way.
+
+**Verification.** Live on the reporting machine: with the launcher published,
+typing "jarvis" returns Personal Jarvis as the best match, categorised as an
+App and carrying the mascot icon — previously the best match was a folder and
+the app appeared only as a Desktop file hit.
+
+**Tests.** `tests/unit/ui/test_msix_redirection.py` (redirection arithmetic as
+a pure function — Start Menu diverted, Desktop not, unpackaged interpreter
+untouched, a container path never shadowed twice; publish moves the file and
+clears the shadow; a failed publish reports failure rather than a phantom
+install; uninstall removes the copy the user actually clicks) and
+`tests/unit/ui/test_desktop_discoverability.py` (the announcement step on
+Linux and macOS, including that an unchanged entry is still announced so a
+half-finished earlier run heals). All run on every OS.
diff --git a/docs/os-parity.md b/docs/os-parity.md
index ed4de34158..8bd4d4c75f 100644
--- a/docs/os-parity.md
+++ b/docs/os-parity.md
@@ -178,6 +178,21 @@ existing macOS Screen Recording gate, Wayland refusal and headless refusal are
unchanged, so an unavailable capture backend never becomes permission to act
blindly. The cross-platform tkinter engine rig remains the release oracle.
+**Fix pass 2026-08-16 (the app is findable as an app).** BUG-138 was a Windows
+defect, but its shape was shared: on all three systems the launcher file was
+written and never announced to the index that answers the user's search, so a
+fresh install sat on disk and appeared only after the next login. Windows now
+publishes the Start-Menu launcher out of the MSIX container a Microsoft-Store
+Python imposes (and reports failure instead of a phantom install); Linux calls
+`update-desktop-database` and ships `Keywords=` so the app search matches the
+half of a two-word product name a user actually types; macOS registers the
+bundle with `lsregister`. Each announcement is capability-probed and degrades
+honestly to "appears after the next rescan" — `desktop-file-utils` is not
+installed everywhere and `lsregister` can be absent from a stripped system —
+so no platform silently claims an entry the shell cannot see. Announcement is
+re-run for an unchanged entry too, which heals an install whose earlier write
+succeeded while its announcement did not.
+
## Audit verdict summary
**No hard breakers found.** No feature crashes on macOS or headless Linux;
diff --git a/jarvis/autostart/windows.py b/jarvis/autostart/windows.py
index 6c3dc34431..327b34986a 100644
--- a/jarvis/autostart/windows.py
+++ b/jarvis/autostart/windows.py
@@ -360,6 +360,16 @@ def _tag_shortcut_aumid(link: Path) -> bool:
propsys.PROPVARIANTType(APP_USER_MODEL_ID),
)
store.Commit()
+ # The .lnk itself is created by a PowerShell child, which is why it
+ # reaches the real Startup folder under a Store Python (BUG-138). This
+ # commit runs IN-PROCESS, so it is redirected: it would leave the real
+ # shortcut untagged and drop a container copy that masks it from every
+ # later in-process read. Publishing puts the tagged version back.
+ from jarvis.ui.msix_redirection import publish_out_of_container
+
+ if not publish_out_of_container(link):
+ log.debug("autostart shortcut AUMID stayed inside the app container")
+ return False
return True
except Exception as exc: # noqa: BLE001 — pywin32 absent / COM failure → icon-only fallback
log.debug("autostart shortcut AUMID not tagged (non-fatal): %s", exc)
diff --git a/jarvis/setup/desktop_integration.py b/jarvis/setup/desktop_integration.py
index 48ef4db711..262f2cc087 100644
--- a/jarvis/setup/desktop_integration.py
+++ b/jarvis/setup/desktop_integration.py
@@ -214,6 +214,32 @@ def _windows_desktop_dir() -> Path | None:
return Path(profile) / "Desktop" if profile else None
+def _remove_shell_launcher(path: Path) -> str | None:
+ """Delete a launcher where the SHELL sees it; return an error or ``None``.
+
+ Under a Microsoft-Store Python this process runs inside an MSIX container
+ that redirects deletes just as it redirects writes, so a plain ``unlink``
+ removes only the container's private copy and leaves the launcher the user
+ actually clicks sitting in the real Start Menu — pointing at an install that
+ no longer exists. The escape helper handles the redirected case and is a
+ no-op on every ordinary interpreter.
+ """
+ try:
+ path.unlink(missing_ok=True)
+ except OSError as exc:
+ # Returned, not logged: the caller turns this into the user-visible
+ # uninstall warning, and logging it here would report it twice.
+ return str(exc)
+ try:
+ from jarvis.ui.msix_redirection import remove_outside_container
+
+ if not remove_outside_container(path):
+ return "the launcher outside the app container could not be removed"
+ except Exception as exc: # noqa: BLE001 - uninstall continues with other artifacts
+ return f"container cleanup failed: {exc}"
+ return None
+
+
def _remove_windows_desktop_integration(
*,
programs_dir: Path | None = None,
@@ -224,18 +250,15 @@ def _remove_windows_desktop_integration(
warnings: list[str] = []
programs = programs_dir or _windows_programs_dir()
if programs is not None:
- shortcut = programs / WINDOWS_SHORTCUT_FILE_NAME
- try:
- shortcut.unlink(missing_ok=True)
- except OSError as exc:
- warnings.append(f"could not remove the Start-menu launcher: {exc}")
+ failure = _remove_shell_launcher(programs / WINDOWS_SHORTCUT_FILE_NAME)
+ if failure is not None:
+ warnings.append(f"could not remove the Start-menu launcher: {failure}")
# An uninstall that leaves an icon on the desktop has not uninstalled.
desktop = desktop_dir or _windows_desktop_dir()
if desktop is not None:
- try:
- (desktop / WINDOWS_SHORTCUT_FILE_NAME).unlink(missing_ok=True)
- except OSError as exc:
- warnings.append(f"could not remove the Desktop launcher: {exc}")
+ failure = _remove_shell_launcher(desktop / WINDOWS_SHORTCUT_FILE_NAME)
+ if failure is not None:
+ warnings.append(f"could not remove the Desktop launcher: {failure}")
if not _delete_windows_registry_key(registry_subkey):
warnings.append("could not remove the Installed Apps registry entry")
if not _delete_windows_registry_key(_windows_aumid_subkey(aumid)):
diff --git a/jarvis/setup/macos_app_bundle.py b/jarvis/setup/macos_app_bundle.py
index 09820ad247..d2e0fe1ab5 100644
--- a/jarvis/setup/macos_app_bundle.py
+++ b/jarvis/setup/macos_app_bundle.py
@@ -296,6 +296,57 @@ def macos_launch_services_command(
return command
+_LSREGISTER = (
+ "/System/Library/Frameworks/CoreServices.framework/Frameworks"
+ "/LaunchServices.framework/Support/lsregister"
+)
+
+
+def register_with_launch_services(bundle: Path) -> bool:
+ """Announce the bundle to LaunchServices so Spotlight can find it.
+
+ Writing the ``.app`` is only half the job. Spotlight, Launchpad and the
+ ``open -a`` name lookup all resolve through the LaunchServices database,
+ which is rebuilt from directory scans that are not immediate — a bundle
+ written into ``~/Applications`` is routinely unsearchable until the next
+ login. ``lsregister`` is the documented way to register one bundle right
+ away, and it is the macOS counterpart of the Windows Start-Menu shell
+ notification and the Linux ``update-desktop-database`` call: without it the
+ freshly installed app is on disk but absent from the user's search.
+
+ Best-effort and idempotent: re-registering an already-known bundle is a
+ no-op for LaunchServices. Returns ``True`` only when the tool ran cleanly;
+ a failure degrades to "appears after the next login", never to an error.
+ """
+ if sys.platform != "darwin":
+ return False
+ tool = Path(_LSREGISTER)
+ if not tool.is_file():
+ log.debug("lsregister not present; relying on the periodic rescan")
+ return False
+ try:
+ result = subprocess.run( # noqa: S603 - fixed system path, no shell
+ [str(tool), "-f", str(bundle)],
+ timeout=60,
+ stdin=subprocess.DEVNULL,
+ capture_output=True,
+ text=True,
+ check=False,
+ )
+ if result.returncode != 0:
+ log.debug(
+ "lsregister failed (rc=%s): %s",
+ result.returncode,
+ (result.stderr or "").strip()[:300],
+ )
+ return False
+ log.debug("Registered with LaunchServices: %s", bundle)
+ return True
+ except Exception as exc: # noqa: BLE001 - search registration is best-effort
+ log.debug("LaunchServices registration skipped: %s", exc)
+ return False
+
+
def _try_build_icns(resources_dir: Path) -> str | None:
"""Best-effort ``jarvis.icns`` creation; never block bundle creation."""
if sys.platform != "darwin":
@@ -740,6 +791,11 @@ def ensure_macos_app_bundle(
if _current_process_identity_valid(
bundle, install_root=install_root
) or _runtime_identity_valid(bundle, install_root=install_root):
+ # A healthy bundle is kept byte-for-byte, but LaunchServices may
+ # still not know it — an interrupted earlier run, or a database
+ # rebuilt since. Re-registering is a no-op when it is known, and
+ # repairs "installed but unsearchable" when it is not.
+ register_with_launch_services(bundle)
return bundle
log.warning(
"Existing macOS bundle failed its runtime/import probe; rebuilding: %s",
@@ -748,6 +804,7 @@ def ensure_macos_app_bundle(
if sys.platform != "darwin":
return _write_cross_platform_fixture_bundle(bundle)
installed = _install_native_bundle(install_root, bundle)
+ register_with_launch_services(installed)
log.info("Native macOS app bundle installed: %s", installed)
return installed
except Exception as exc: # noqa: BLE001 - installer consumes the None result
@@ -783,5 +840,6 @@ __all__ = [
"macos_app_bundle_is_launchable",
"macos_app_bundle_path",
"macos_launch_services_command",
+ "register_with_launch_services",
"remove_macos_app_bundle",
]
diff --git a/jarvis/ui/icon_utils.py b/jarvis/ui/icon_utils.py
index 7d5e2c3e84..9b92fa7777 100644
--- a/jarvis/ui/icon_utils.py
+++ b/jarvis/ui/icon_utils.py
@@ -716,6 +716,15 @@ def ensure_start_menu_shortcut(
lnk = programs / START_MENU_SHORTCUT_NAME
iid = pywintypes.IID(_IID_IPROPERTYSTORE)
+ # Every check below asks the file system what is in the Start Menu. Under a
+ # Store Python those reads are answered from the package container first, so
+ # a copy trapped there by an older build would look like a healthy entry and
+ # this function would return True while the shell still sees nothing.
+ # Dropping the shadow first makes the reads report what the shell reports.
+ from jarvis.ui.msix_redirection import reveal_real_path
+
+ reveal_real_path(lnk)
+
if not _interpreter_can_open_a_window():
# This interpreter cannot start the desktop app, so it must not become
# the shortcut's target. Leave whatever is there — a working entry from
@@ -795,6 +804,16 @@ def _write_branded_shortcut(
)
rw_store.SetValue(pscon.PKEY_AppUserModel_ID, propsys.PROPVARIANTType(aumid))
rw_store.Commit()
+ # Under a Microsoft-Store Python every write above was diverted into the
+ # package's private container, so the shortcut we just "saved into the
+ # Start Menu" is invisible to the shell. Publishing it out is what makes
+ # the entry real; a failure here means the app is NOT installed as far as
+ # Windows is concerned, so it must not be reported as a success.
+ from jarvis.ui.msix_redirection import publish_out_of_container
+
+ if not publish_out_of_container(lnk):
+ logger.debug("shortcut stayed trapped in the MSIX container: {}", lnk)
+ return False
_notify_shell_of_shortcut(lnk)
return True
except Exception as exc: # noqa: BLE001
@@ -845,6 +864,13 @@ def ensure_desktop_shortcut(
ico = icon_path or project_icon_path()
lnk = desktop / START_MENU_SHORTCUT_NAME
+ # Normally a no-op — the Desktop is not one of the redirected roots — but a
+ # profile that relocates it under %LOCALAPPDATA% would hit the same trap as
+ # the Start Menu, and the check costs a path comparison.
+ from jarvis.ui.msix_redirection import reveal_real_path
+
+ reveal_real_path(lnk)
+
if not lnk.is_file() and not create_if_missing:
return False
if not _interpreter_can_open_a_window():
@@ -1330,6 +1356,59 @@ def _default_linux_applications_dir() -> Path:
return base / "applications"
+def _refresh_linux_desktop_database(applications_dir: Path) -> bool:
+ """Tell the desktop shell a new application entry exists.
+
+ Writing the ``.desktop`` file is only half the job, exactly as on Windows:
+ GNOME, KDE and friends answer app searches from ``mimeinfo.cache`` /
+ ``desktop.<arch>.cache`` built by ``update-desktop-database``, not by reading
+ the folder on every keystroke. Without this call the entry typically appears
+ only after the next login — the Linux twin of the Windows Start-Menu index
+ problem, and the reason a fresh install "isn't in the search" while the file
+ is demonstrably on disk.
+
+ Best-effort by design: ``update-desktop-database`` ships with
+ ``desktop-file-utils``, which is not installed everywhere, and several
+ desktops watch the directory with inotify and need no prompting at all. A
+ missing tool therefore degrades to "appears after the next login", never to
+ an error. Returns ``True`` only when the database was actually rebuilt.
+ """
+ if sys.platform != "linux":
+ return False
+ import shutil
+
+ tool = shutil.which("update-desktop-database")
+ if tool is None:
+ logger.debug(
+ "update-desktop-database not installed; the menu entry appears "
+ "once the desktop rescans (usually at next login)"
+ )
+ return False
+ try:
+ import subprocess
+
+ result = subprocess.run( # noqa: S603 — resolved absolute path, no shell
+ [tool, str(applications_dir)],
+ timeout=30,
+ stdin=subprocess.DEVNULL,
+ capture_output=True,
+ text=True,
+ check=False,
+ )
+ if result.returncode != 0:
+ logger.debug(
+ "update-desktop-database failed (rc={}): {}",
+ result.returncode,
+ (result.stderr or "").strip()[:300],
+ )
+ return False
+ logger.debug("desktop database refreshed for {}", applications_dir)
+ return True
+ except Exception as exc: # noqa: BLE001 — never block the window on a menu refresh
+ logger.debug("desktop database could not be refreshed: {}", exc)
+ return False
+
+
def ensure_linux_desktop_entry(applications_dir: Path | None = None) -> bool:
"""Install/refresh the applications-menu ``.desktop`` entry (Linux only).
@@ -1374,12 +1453,25 @@ def ensure_linux_desktop_entry(applications_dir: Path | None = None) -> bool:
f"{icon_line}"
f"StartupWMClass={escape_value(LINUX_WM_CLASS)}\n"
"Categories=Utility;\n"
+ # The app search matches Name, and only some shells also match
+ # Comment — the product name is two words, so a user typing the
+ # half they remember ("jarvis", or what the assistant is FOR) needs
+ # these to be hit at all. Same role as the Windows Start-Menu file
+ # name being the searchable token.
+ "Keywords=jarvis;assistant;voice;agent;automation;\n"
)
entry = applications_dir / LINUX_DESKTOP_ENTRY_NAME
try:
if entry.read_text(encoding="utf-8") == content:
+ # Content is current, but the menu database may still not know
+ # the entry — an interrupted earlier run could have written the
+ # file and never registered it. Re-announcing is cheap and
+ # idempotent, so a repaired install never needs a re-login.
+ _refresh_linux_desktop_database(applications_dir)
return True
except OSError:
+ # No readable entry yet (first install, or an unreadable leftover):
+ # that is the normal path into the write below, not a fault.
pass
applications_dir.mkdir(parents=True, exist_ok=True)
# Atomic-ish (same idiom as the autostart entry): never leave a
@@ -1387,6 +1479,12 @@ def ensure_linux_desktop_entry(applications_dir: Path | None = None) -> bool:
tmp = entry.with_name(entry.name + ".tmp")
tmp.write_text(content, encoding="utf-8")
tmp.replace(entry)
+ try:
+ # Some shells refuse to offer an entry that is not user-executable.
+ entry.chmod(0o755)
+ except OSError as exc:
+ logger.debug("could not mark {} executable: {}", entry, exc)
+ _refresh_linux_desktop_database(applications_dir)
logger.debug("Linux applications .desktop entry written: {}", entry)
return True
except Exception as exc: # noqa: BLE001 — menu entry is a nicety, never load-bearing
diff --git a/jarvis/ui/msix_redirection.py b/jarvis/ui/msix_redirection.py
new file mode 100644
index 0000000000..86ce74b512
--- /dev/null
+++ b/jarvis/ui/msix_redirection.py
@@ -0,0 +1,349 @@
+"""Escape the MSIX file-system redirection a Microsoft-Store Python imposes.
+
+Why this module exists — the forensic, because the symptom lies:
+
+A Python installed from the Microsoft Store runs every child interpreter inside
+the store package's MSIX container, and a venv built from it inherits that
+identity. Windows then silently redirects the container's writes to
+``%APPDATA%`` and ``%LOCALAPPDATA%`` into a private per-package tree under
+``%LOCALAPPDATA%\\Packages\\<family>\\LocalCache``. The per-user Start Menu
+lives in ``%APPDATA%``, so the launcher we write "into the Start Menu" is
+diverted into that container and the shell never sees it: the app is absent
+from Windows Search and from the Start menu, while the Desktop launcher — the
+Desktop is NOT a redirected location — keeps working. That is exactly the
+2026-08-16 report: "only the Desktop icon starts it".
+
+The redirection is invisible from the inside. Reads are redirected the same
+way, so ``lnk.is_file()`` answers ``True`` for the trapped copy: every layer we
+had reported success while the shell saw nothing, and an earlier session
+concluded the machine's app index was broken. It was not — the file simply was
+never there.
+
+The escape has two halves, both required:
+
+* **Publish** through a helper process that has no package identity, which is
+ the only way to write into the real tree. ``powershell.exe`` from System32
+ qualifies: Windows does not hand package identity to it (verified live).
+* **Drop the shadow** afterwards, because MSIX resolves reads container-first
+ and falls through to the real path only when the container copy is gone.
+ Removing it is what makes our own later ``is_file()`` checks honest, so the
+ idempotence and staleness logic upstream reasons about what the shell sees.
+
+Everything here is a no-op off Windows and on an unpackaged interpreter (the
+regular python.org install, where nothing is redirected), and best-effort
+throughout: shell registration must never raise and never block boot.
+"""
+
+from __future__ import annotations
+
+import os
+import subprocess
+import sys
+from pathlib import Path
+
+from loguru import logger
+
+# GetCurrentPackageFamilyName's way of saying "this process has no package
+# identity" — i.e. a normal, unpackaged interpreter with no redirection at all.
+_APPMODEL_ERROR_NO_PACKAGE = 15700
+# ...and its way of saying "you have identity, the name needs this much room".
+_ERROR_INSUFFICIENT_BUFFER = 122
+
+# Resolved once: the answer cannot change within a process, and the probe sits
+# on the boot path (AP-26 — nothing heavy on the critical path).
+_FAMILY_PROBED = False
+_FAMILY: str | None = None
+
+
+def package_family_name() -> str | None:
+ """The MSIX package family hosting this process, or ``None`` when unpackaged.
+
+ ``GetCurrentPackageFamilyName`` is the documented identity probe and the
+ only trustworthy one: the interpreter path is not a reliable signal, since a
+ venv built from a Store Python reports its own ``Scripts\\python.exe`` in
+ ``sys.executable`` while still running inside the container.
+
+ Cached, Windows-only, never raises. ``kernel32`` gained this export in
+ Windows 8, so an older or stripped system simply reports "unpackaged".
+ """
+ global _FAMILY_PROBED, _FAMILY
+
+ if _FAMILY_PROBED:
+ return _FAMILY
+ _FAMILY_PROBED = True
+ if sys.platform != "win32":
+ return None
+ try:
+ import ctypes
+ from ctypes import wintypes
+
+ kernel32 = ctypes.windll.kernel32
+ probe = kernel32.GetCurrentPackageFamilyName
+ probe.argtypes = [ctypes.POINTER(wintypes.UINT), wintypes.LPWSTR]
+ probe.restype = wintypes.LONG
+
+ length = wintypes.UINT(0)
+ rc = probe(ctypes.byref(length), None)
+ if rc == _APPMODEL_ERROR_NO_PACKAGE:
+ return None
+ if rc != _ERROR_INSUFFICIENT_BUFFER:
+ logger.debug("package identity probe returned {}; assuming unpackaged", rc)
+ return None
+ buffer = ctypes.create_unicode_buffer(length.value)
+ if probe(ctypes.byref(length), buffer) != 0:
+ return None
+ _FAMILY = buffer.value or None
+ if _FAMILY:
+ logger.debug("running inside MSIX package family {}", _FAMILY)
+ return _FAMILY
+ except Exception as exc: # noqa: BLE001 — an unprobeable host is an unpackaged one
+ logger.debug("package identity could not be probed: {}", exc)
+ return None
+
+
+def _is_relative_to(path: Path, root: Path) -> bool:
+ """``Path.is_relative_to`` with Windows' case-insensitive comparison."""
+ try:
+ candidate = os.path.normcase(os.path.abspath(path))
+ base = os.path.normcase(os.path.abspath(root))
+ except (OSError, ValueError):
+ # A path this malformed cannot be under a redirected root either, and
+ # the honest answer to "is it?" is no. Logging here would fire on every
+ # shortcut check for a profile with an odd env var, for no new fact.
+ return False
+ return candidate == base or candidate.startswith(base + os.sep)
+
+
+def shadow_path_for(
+ path: Path,
+ *,
+ family: str | None,
+ local_appdata: str | Path | None,
+ roaming_appdata: str | Path | None,
+) -> Path | None:
+ """Where a packaged process's write to ``path`` really lands.
+
+ The two redirected roots are documented for the Desktop Bridge:
+ ``%LOCALAPPDATA%`` maps into ``LocalCache\\Local`` and roaming ``%APPDATA%``
+ into ``LocalCache\\Roaming``. ``%LOCALAPPDATA%\\Packages`` is deliberately
+ NOT redirected — it holds the containers themselves — which is what lets us
+ address a shadow copy directly instead of only through the redirection.
+
+ Returns ``None`` when nothing is redirected: no package identity, or a
+ target outside both roots (the Desktop, Program Files, the install tree).
+
+ Pure and platform-neutral so the arithmetic that decides whether the shell
+ can see a launcher stays testable on every CI runner; the environment
+ lookup lives in :func:`container_shadow_path`.
+ """
+ if not family or not local_appdata:
+ return None
+ local = Path(local_appdata)
+ # The containers live UNDER %LOCALAPPDATA%, so this exception has to be
+ # checked before the roots below or every shadow path would itself resolve
+ # to a shadow — addressing a trapped file directly (to publish or clear it)
+ # would then aim one level deeper on each call.
+ if _is_relative_to(path, local / "Packages"):
+ return None
+ cache = local / "Packages" / family / "LocalCache"
+ pairs: list[tuple[Path, Path]] = [(local, cache / "Local")]
+ if roaming_appdata:
+ pairs.append((Path(roaming_appdata), cache / "Roaming"))
+
+ for real_root, container_root in pairs:
+ # A path already inside a container is the shadow, not a source for one.
+ if _is_relative_to(path, container_root):
+ return None
+ if _is_relative_to(path, real_root):
+ try:
+ return container_root / path.relative_to(real_root)
+ except ValueError: # differing case defeated relative_to
+ tail = os.path.abspath(path)[len(os.path.abspath(real_root)) :]
+ return container_root / tail.lstrip(os.sep)
+ return None
+
+
+def container_shadow_path(path: Path) -> Path | None:
+ """Where a write to ``path`` really lands, or ``None`` when it lands there.
+
+ ``None`` covers every ordinary install — off Windows, on an unpackaged
+ interpreter, or for a target outside the redirected roots. Callers treat
+ ``None`` as "nothing to do".
+ """
+ if sys.platform != "win32":
+ return None
+ return shadow_path_for(
+ path,
+ family=package_family_name(),
+ local_appdata=os.environ.get("LOCALAPPDATA"),
+ roaming_appdata=os.environ.get("APPDATA"),
+ )
+
+
+def _powershell() -> str:
+ """The Windows PowerShell binary, addressed absolutely where we can.
+
+ An absolute path keeps the helper off ``PATH``, which a user profile can
+ point anywhere — this process is about to hand it a file to copy.
+ """
+ system_root = os.environ.get("SystemRoot")
+ if system_root:
+ candidate = Path(system_root) / "System32" / "WindowsPowerShell" / "v1.0" / "powershell.exe"
+ if candidate.is_file():
+ return str(candidate)
+ return "powershell.exe"
+
+
+# Each script ends by proving its own outcome from OUTSIDE the container, so the
+# exit code answers "does the shell see what we intended?" rather than "did the
+# command not throw". Paths travel in the environment, never on the command
+# line: no quoting rules to get wrong for a path holding a space, a quote or a
+# dollar sign, and no way for a path to become script.
+_PUBLISH_SCRIPT = (
+ "$ErrorActionPreference = 'Stop'; "
+ "$src = $env:JARVIS_MSIX_SRC; $dst = $env:JARVIS_MSIX_DST; "
+ "New-Item -ItemType Directory -Force -Path (Split-Path -Parent $dst) "
+ "| Out-Null; "
+ "Copy-Item -LiteralPath $src -Destination $dst -Force; "
+ "if (Test-Path -LiteralPath $dst) { exit 0 } else { exit 1 }"
+)
+
+_REMOVE_SCRIPT = (
+ "$dst = $env:JARVIS_MSIX_DST; "
+ "Remove-Item -LiteralPath $dst -Force -ErrorAction SilentlyContinue; "
+ "if (Test-Path -LiteralPath $dst) { exit 1 } else { exit 0 }"
+)
+
+
+def _run_helper(script: str, **paths: Path) -> bool:
+ """Run one PowerShell script outside the container; ``True`` on exit code 0."""
+ try:
+ from jarvis.core.process_utils import NO_WINDOW_CREATIONFLAGS
+
+ env = dict(os.environ)
+ for name, value in paths.items():
+ env[f"JARVIS_MSIX_{name.upper()}"] = str(value)
+ result = subprocess.run( # noqa: S603 — fixed argv, no shell, System32 binary
+ [
+ _powershell(),
+ "-NoProfile",
+ "-NonInteractive",
+ "-ExecutionPolicy",
+ "Bypass",
+ "-Command",
+ script,
+ ],
+ env=env,
+ timeout=60,
+ creationflags=NO_WINDOW_CREATIONFLAGS,
+ stdin=subprocess.DEVNULL,
+ capture_output=True,
+ text=True,
+ encoding="utf-8",
+ errors="replace",
+ )
+ if result.returncode != 0:
+ logger.debug(
+ "MSIX helper failed (rc={}) for {}: {}",
+ result.returncode,
+ paths,
+ (result.stderr or "").strip()[:400],
+ )
+ return False
+ return True
+ except Exception as exc: # noqa: BLE001 — best-effort, never blocks boot
+ logger.debug("MSIX helper could not run for {}: {}", paths, exc)
+ return False
+
+
+def publish_out_of_container(path: Path) -> bool:
+ """Move a redirected write to where the shell can see it.
+
+ Returns ``True`` when ``path`` needs no escaping (the common case: an
+ unpackaged interpreter, or a target outside the redirected roots) or when
+ the trapped copy was successfully published. ``False`` means the file is
+ still only inside the container — the caller should report the artifact as
+ not installed rather than claim a success the shell cannot see.
+
+ Safe to call on a path that was never written: an absent shadow is simply
+ nothing to do.
+ """
+ shadow = container_shadow_path(path)
+ if shadow is None:
+ return True
+ try:
+ if not shadow.is_file():
+ return True
+ except OSError:
+ # An unreadable container path means nothing is trapped there to
+ # publish, so the caller's write already went where it should. Treated
+ # as "nothing to do" rather than a failure the caller must report.
+ return True
+ if not _run_helper(_PUBLISH_SCRIPT, src=shadow, dst=path):
+ return False
+ # Drop the shadow so later reads fall through to the real file. Without
+ # this, every subsequent is_file()/staleness check in this process keeps
+ # answering from the container and the caller can never tell the two apart.
+ try:
+ shadow.unlink()
+ except OSError as exc:
+ logger.debug("container shadow could not be removed at {}: {}", shadow, exc)
+ logger.debug("published out of the MSIX container: {}", path)
+ return True
+
+
+def reveal_real_path(path: Path) -> None:
+ """Remove a stale container copy so reads of ``path`` see the real file.
+
+ Called before the idempotence checks so they reason about what the shell
+ sees, not about a copy trapped by an earlier run of an older build. Only
+ ever deletes inside this process's own container.
+ """
+ shadow = container_shadow_path(path)
+ if shadow is None:
+ return
+ try:
+ if shadow.is_file():
+ shadow.unlink()
+ logger.debug("cleared stale MSIX container copy: {}", shadow)
+ except OSError as exc:
+ logger.debug("stale container copy could not be cleared at {}: {}", shadow, exc)
+
+
+def remove_outside_container(path: Path) -> bool:
+ """Delete ``path`` where the shell sees it, container copy included.
+
+ Deletion is redirected exactly like writing, so an uninstall running under a
+ Store Python removes only its own container copy: the launcher stays in the
+ real Start Menu, the caller reports a clean uninstall, and the user is left
+ with an entry that starts a deleted install. Reaching the real file needs
+ the same unpackaged helper the install path uses.
+
+ Returns ``True`` when the path is gone (or was never redirected, in which
+ case the caller's own ``unlink`` is authoritative and this is a no-op).
+ """
+ shadow = container_shadow_path(path)
+ if shadow is None:
+ return True
+ try:
+ if shadow.is_file():
+ shadow.unlink()
+ except OSError as exc:
+ logger.debug("container copy could not be removed at {}: {}", shadow, exc)
+ return _run_helper(_REMOVE_SCRIPT, dst=path)
+
+
+def redirects_writes(path: Path) -> bool:
+ """Would a write to ``path`` be diverted into this process's container?"""
+ return container_shadow_path(path) is not None
+
+
+__all__ = [
+ "container_shadow_path",
+ "package_family_name",
+ "publish_out_of_container",
+ "redirects_writes",
+ "remove_outside_container",
+ "reveal_real_path",
+ "shadow_path_for",
+]
diff --git a/tests/unit/ui/test_desktop_discoverability.py b/tests/unit/ui/test_desktop_discoverability.py
new file mode 100644
index 0000000000..3160284f0c
--- /dev/null
+++ b/tests/unit/ui/test_desktop_discoverability.py
@@ -0,0 +1,155 @@
+"""Being installed is not the same as being findable.
+
+Each desktop has an index between the launcher file and the user's search box —
+the Windows app index, the XDG desktop database, LaunchServices — and writing
+the file without announcing it leaves the app on disk but absent from search
+until the next login. That is the shape of the 2026-08-16 report, and these
+tests pin the announcement on every platform.
+"""
+
+from __future__ import annotations
+
+import subprocess
+import sys
+from pathlib import Path
+
+import pytest
+
+from jarvis.setup import macos_app_bundle
+from jarvis.ui import icon_utils
+
+
+def _entry(applications_dir: Path) -> Path:
+ return applications_dir / "personal-jarvis.desktop"
+
+
+def test_linux_entry_carries_search_keywords(tmp_path: Path) -> None:
+ """The name is two words; a user types the half they remember."""
+ apps = tmp_path / "applications"
+
+ assert icon_utils.ensure_linux_desktop_entry(applications_dir=apps) is True
+
+ content = _entry(apps).read_text(encoding="utf-8")
+ assert "Keywords=" in content
+ keywords = next(
+ line.split("=", 1)[1] for line in content.splitlines() if line.startswith("Keywords=")
+ )
+ assert "jarvis" in keywords
+ assert keywords.endswith(";")
+
+
+def test_linux_entry_is_announced_to_the_desktop_database(
+ tmp_path: Path, monkeypatch: pytest.MonkeyPatch
+) -> None:
+ """Without this the entry shows up only after the next login."""
+ apps = tmp_path / "applications"
+ announced: list[Path] = []
+ monkeypatch.setattr(
+ icon_utils,
+ "_refresh_linux_desktop_database",
+ lambda directory: announced.append(directory) or True,
+ )
+
+ icon_utils.ensure_linux_desktop_entry(applications_dir=apps)
+
+ assert announced == [apps]
+
+
+def test_an_unchanged_linux_entry_is_still_announced(
+ tmp_path: Path, monkeypatch: pytest.MonkeyPatch
+) -> None:
+ """An install whose write succeeded but whose announcement did not must heal.
+
+ The content check short-circuits the rewrite; if it also skipped the
+ announcement, a half-finished earlier run would stay unsearchable forever.
+ """
+ apps = tmp_path / "applications"
+ icon_utils.ensure_linux_desktop_entry(applications_dir=apps)
+
+ announced: list[Path] = []
+ monkeypatch.setattr(
+ icon_utils,
+ "_refresh_linux_desktop_database",
+ lambda directory: announced.append(directory) or True,
+ )
+
+ assert icon_utils.ensure_linux_desktop_entry(applications_dir=apps) is True
+ assert announced == [apps]
+
+
[email protected](sys.platform == "win32", reason="POSIX permission bits")
+def test_linux_entry_is_executable(tmp_path: Path) -> None:
+ """Some shells refuse to offer an entry that is not user-executable."""
+ apps = tmp_path / "applications"
+
+ icon_utils.ensure_linux_desktop_entry(applications_dir=apps)
+
+ assert _entry(apps).stat().st_mode & 0o100
+
+
+def test_missing_update_tool_degrades_to_a_later_rescan(
+ tmp_path: Path, monkeypatch: pytest.MonkeyPatch
+) -> None:
+ """desktop-file-utils is not installed everywhere; that is not an error."""
+ monkeypatch.setattr(sys, "platform", "linux")
+ monkeypatch.setattr("shutil.which", lambda _name: None)
+ monkeypatch.setattr(
+ subprocess,
+ "run",
+ lambda *a, **k: pytest.fail("no tool means no subprocess"),
+ )
+
+ assert icon_utils._refresh_linux_desktop_database(tmp_path) is False
+
+
+def test_linux_refresh_targets_the_applications_dir(
+ tmp_path: Path, monkeypatch: pytest.MonkeyPatch
+) -> None:
+ monkeypatch.setattr(sys, "platform", "linux")
+ monkeypatch.setattr("shutil.which", lambda _name: "/usr/bin/update-desktop-database")
+ calls: list[list[str]] = []
+
+ class _Result:
+ returncode = 0
+ stderr = ""
+
+ def _run(argv, **_kwargs):
+ calls.append(argv)
+ return _Result()
+
+ monkeypatch.setattr(subprocess, "run", _run)
+
+ assert icon_utils._refresh_linux_desktop_database(tmp_path) is True
+ assert calls == [["/usr/bin/update-desktop-database", str(tmp_path)]]
+
+
+def test_launch_services_registration_is_a_noop_off_macos() -> None:
+ """Every other OS reaches this through its own index, never lsregister."""
+ if sys.platform == "darwin":
+ pytest.skip("this asserts the non-macOS branch")
+
+ assert macos_app_bundle.register_with_launch_services(Path("/x/Personal Jarvis.app")) is False
+
+
+def test_launch_services_registration_forces_the_bundle(
+ tmp_path: Path, monkeypatch: pytest.MonkeyPatch
+) -> None:
+ """``-f`` re-registers a bundle LaunchServices may already have stale."""
+ monkeypatch.setattr(sys, "platform", "darwin")
+ monkeypatch.setattr(Path, "is_file", lambda self: True)
+ calls: list[list[str]] = []
+
+ class _Result:
+ returncode = 0
+ stderr = ""
+
+ def _run(argv, **_kwargs):
+ calls.append(argv)
+ return _Result()
+
+ monkeypatch.setattr(subprocess, "run", _run)
+ bundle = tmp_path / "Personal Jarvis.app"
+
+ assert macos_app_bundle.register_with_launch_services(bundle) is True
+ assert calls[0][1:] == ["-f", str(bundle)]
+ assert calls[0][0].endswith("lsregister")
diff --git a/tests/unit/ui/test_msix_redirection.py b/tests/unit/ui/test_msix_redirection.py
new file mode 100644
index 0000000000..3361edf327
--- /dev/null
+++ b/tests/unit/ui/test_msix_redirection.py
@@ -0,0 +1,191 @@
+"""The MSIX container escape that decides whether the shell sees a launcher.
+
+Everything here runs on every OS: the redirection arithmetic is a pure function
+and the escape itself is exercised through an injected helper, so the behaviour
+that broke Windows Search is covered on a Linux CI runner too.
+"""
+
+from __future__ import annotations
+
+from pathlib import Path
+
+import pytest
+
+from jarvis.ui import msix_redirection as mr
+
+FAMILY = "PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0"
+
+
+def roots(tmp_path: Path) -> dict[str, Path]:
+ """A profile shaped like the redirected one, on the running OS's paths."""
+ local = tmp_path / "Local"
+ roaming = tmp_path / "Roaming"
+ programs = roaming / "Microsoft" / "Windows" / "Start Menu" / "Programs"
+ programs.mkdir(parents=True)
+ return {
+ "local": local,
+ "roaming": roaming,
+ "programs": programs,
+ "cache": local / "Packages" / FAMILY / "LocalCache",
+ }
+
+
+def _shadow(path: Path, roots: dict[str, Path], *, family: str | None = FAMILY):
+ return mr.shadow_path_for(
+ path,
+ family=family,
+ local_appdata=roots["local"],
+ roaming_appdata=roots["roaming"],
+ )
+
+
+def test_start_menu_write_is_diverted_into_the_package_container(roots) -> None:
+ """The bug: the launcher never reaches the folder the shell reads."""
+ lnk = roots["programs"] / "Personal Jarvis.lnk"
+
+ shadow = _shadow(lnk, roots)
+
+ assert shadow is not None
+ expected = (
+ roots["cache"]
+ / "Roaming"
+ / "Microsoft"
+ / "Windows"
+ / "Start Menu"
+ / "Programs"
+ / "Personal Jarvis.lnk"
+ )
+ assert shadow == expected
+
+
+def test_local_appdata_is_redirected_too(roots) -> None:
+ target = roots["local"] / "PersonalJarvis" / "bin" / "PersonalJarvis.exe"
+
+ shadow = _shadow(target, roots)
+
+ assert shadow == roots["cache"] / "Local" / "PersonalJarvis" / "bin" / ("PersonalJarvis.exe")
+
+
+def test_an_unpackaged_interpreter_redirects_nothing(roots) -> None:
+ """The ordinary python.org install must take the plain write path."""
+ lnk = roots["programs"] / "Personal Jarvis.lnk"
+
+ assert _shadow(lnk, roots, family=None) is None
+
+
+def test_the_desktop_is_not_redirected(tmp_path: Path, roots) -> None:
+ """Why the Desktop icon kept working while the Start-Menu entry vanished."""
+ desktop = tmp_path / "Desktop" / "Personal Jarvis.lnk"
+
+ assert _shadow(desktop, roots) is None
+
+
+def test_a_path_inside_the_container_is_not_shadowed_again(roots) -> None:
+ """The shadow is addressed directly; it must not resolve to a shadow of one."""
+ shadow = roots["cache"] / "Roaming" / "Microsoft" / "x.lnk"
+
+ assert _shadow(shadow, roots) is None
+
+
+def test_publish_moves_the_trapped_file_and_clears_the_shadow(
+ roots, monkeypatch: pytest.MonkeyPatch
+) -> None:
+ """The escape: file lands where the shell reads, container copy goes away."""
+ lnk = roots["programs"] / "Personal Jarvis.lnk"
+ shadow = _shadow(lnk, roots)
+ assert shadow is not None
+ shadow.parent.mkdir(parents=True)
+ shadow.write_bytes(b"shortcut")
+
+ monkeypatch.setattr(mr, "container_shadow_path", lambda p: shadow)
+
+ def _fake_helper(script: str, **paths: Path) -> bool:
+ # Stands in for the unpackaged process: a real copy into the real tree.
+ assert paths["src"] == shadow
+ assert paths["dst"] == lnk
+ paths["dst"].write_bytes(paths["src"].read_bytes())
+ return True
+
+ monkeypatch.setattr(mr, "_run_helper", _fake_helper)
+
+ assert mr.publish_out_of_container(lnk) is True
+ assert lnk.read_bytes() == b"shortcut"
+ # Without this the next is_file() answers from the container and every
+ # staleness check upstream reasons about a file the shell cannot see.
+ assert not shadow.exists()
+
+
+def test_publish_reports_failure_when_the_file_stays_trapped(
+ roots, monkeypatch: pytest.MonkeyPatch
+) -> None:
+ """A launcher only the container can see must never count as installed."""
+ lnk = roots["programs"] / "Personal Jarvis.lnk"
+ shadow = _shadow(lnk, roots)
+ assert shadow is not None
+ shadow.parent.mkdir(parents=True)
+ shadow.write_bytes(b"shortcut")
+
+ monkeypatch.setattr(mr, "container_shadow_path", lambda p: shadow)
+ monkeypatch.setattr(mr, "_run_helper", lambda *a, **k: False)
+
+ assert mr.publish_out_of_container(lnk) is False
+ # The trapped copy is kept: it is the only version that exists.
+ assert shadow.is_file()
+
+
+def test_publish_is_a_noop_without_redirection(roots, monkeypatch) -> None:
+ lnk = roots["programs"] / "Personal Jarvis.lnk"
+ monkeypatch.setattr(mr, "container_shadow_path", lambda p: None)
+ monkeypatch.setattr(mr, "_run_helper", lambda *a, **k: pytest.fail("helper must not run"))
+
+ assert mr.publish_out_of_container(lnk) is True
+
+
+def test_reveal_drops_a_stale_container_copy(roots, monkeypatch) -> None:
+ """So the idempotence checks upstream see what the shell sees."""
+ lnk = roots["programs"] / "Personal Jarvis.lnk"
+ shadow = _shadow(lnk, roots)
+ assert shadow is not None
+ shadow.parent.mkdir(parents=True)
+ shadow.write_bytes(b"stale")
+ monkeypatch.setattr(mr, "container_shadow_path", lambda p: shadow)
+
+ mr.reveal_real_path(lnk)
+
+ assert not shadow.exists()
+
+
+def test_remove_deletes_the_copy_the_user_actually_clicks(roots, monkeypatch) -> None:
+ """An uninstall must not leave a launcher for a deleted install."""
+ lnk = roots["programs"] / "Personal Jarvis.lnk"
+ lnk.write_bytes(b"real")
+ shadow = _shadow(lnk, roots)
+ assert shadow is not None
+ shadow.parent.mkdir(parents=True)
+ shadow.write_bytes(b"container")
+ monkeypatch.setattr(mr, "container_shadow_path", lambda p: shadow)
+
+ removed: list[Path] = []
+
+ def _fake_helper(script: str, **paths: Path) -> bool:
+ paths["dst"].unlink()
+ removed.append(paths["dst"])
+ return True
+
+ monkeypatch.setattr(mr, "_run_helper", _fake_helper)
+
+ assert mr.remove_outside_container(lnk) is True
+ assert removed == [lnk]
+ assert not lnk.exists()
+ assert not shadow.exists()
+
+
+def test_helper_scripts_take_their_paths_from_the_environment() -> None:
+ """A path holding a quote or a space must never become script."""
+ for script in (mr._PUBLISH_SCRIPT, mr._REMOVE_SCRIPT):
+ assert "$env:JARVIS_MSIX_" in script
+ # Each script proves its own outcome from outside the container instead of
+ # trusting that the command did not throw.
+ assert "Test-Path" in mr._PUBLISH_SCRIPT
+ assert "Test-Path" in mr._REMOVE_SCRIPT