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.
Python agent-orchestrationai-agentai-coding-assistantclaude-codecoding-agentcomputer-usedesktop-applocal-firstmcppersonal-jarvisvoice-assistantvoice-coding
fix(browser): bundle pinned crypto wheel for Intel Mac installs
rubenluetke10-beepcbad05cc47e8
diff --git a/.gitignore b/.gitignoreindex 9aaa438b04..330379a266 100644--- a/.gitignore+++ b/.gitignore@@ -185,6 +185,8 @@ wiki/wiki-backups/scripts/_*.pngscripts/_*.jsonscripts/_flow_in_browser.png+jarvis/assets/browser/wheels/+jarvis/assets/browser/requirements-bundled.lock# IDE / OS.vscode/diff --git a/jarvis/society/browser/install.py b/jarvis/society/browser/install.pyindex 03ce066093..8794d350a1 100644--- a/jarvis/society/browser/install.py+++ b/jarvis/society/browser/install.py@@ -39,7 +39,20 @@ def runner_path() -> Path:def requirements_path() -> Path:- return Path(__file__).resolve().parents[2] / "assets" / "browser" / "requirements.lock"+ assets = Path(__file__).resolve().parents[2] / "assets" / "browser"+ bundled = assets / "requirements-bundled.lock"+ if getattr(sys, "frozen", False) and bundled.is_file():+ return bundled+ return assets / "requirements.lock"+++def bundled_wheel_args() -> list[str]:+ """A native package can carry compiler-built wheels with a matching lock."""+ lock = requirements_path()+ wheels = lock.with_name("wheels")+ if lock.name == "requirements-bundled.lock" and wheels.is_dir():+ return ["--find-links", str(wheels), "--only-binary", "cryptography"]+ return []def managed_python_request(system: str, machine: str) -> str:@@ -272,6 +285,7 @@ def ensure_installed("install","--disable-pip-version-check","--require-hashes",+ *bundled_wheel_args(),"-r",str(requirements_path()),],diff --git a/packaging/macos/build.sh b/packaging/macos/build.shindex f973272f33..335e3191d4 100755--- a/packaging/macos/build.sh+++ b/packaging/macos/build.sh@@ -128,6 +128,9 @@ elserun "${PYTHON}" "${SCRIPT_DIR}/make_icns.py"fi+log "preparing compiler-free browser dependencies"+run "${PYTHON}" "${REPO_ROOT}/scripts/prepare_browser_wheelhouse.py"+log "running PyInstaller"(cd "${REPO_ROOT}"diff --git a/scripts/prepare_browser_wheelhouse.py b/scripts/prepare_browser_wheelhouse.pynew file mode 100644index 0000000000..23a5a41029--- /dev/null+++ b/scripts/prepare_browser_wheelhouse.py@@ -0,0 +1,109 @@+"""Build the pinned crypto wheel for Intel Mac packages, never on the user's Mac.++Cryptography 49+ no longer publishes Intel Mac wheels. Keep the current version+and build a statically linked wheel on the publisher's toolchain instead of+requiring Rust/Xcode at first run or downgrading the user's crypto dependency.+"""++from __future__ import annotations++import hashlib+import os+import platform+import re+import subprocess+import sys+import tempfile+import zipfile+from pathlib import Path++ROOT = Path(__file__).resolve().parents[1]+sys.path.insert(0, str(ROOT))++from jarvis.core.process_utils import NO_WINDOW_CREATIONFLAGS # noqa: E402+++def crypto_requirement(lock: str) -> str:+ match = re.search(r"^cryptography==[^\n]+(?:\n[ \t]+[^\n]*)*", lock, re.MULTILINE)+ if match is None:+ raise ValueError("Browser lock does not pin cryptography")+ return match.group()+++def add_wheel_hash(lock: str, wheel: Path) -> str:+ block = crypto_requirement(lock)+ version = block.splitlines()[0].split("==", 1)[1].split()[0]+ if not wheel.name.startswith(f"cryptography-{version}-"):+ raise ValueError("Built wheel does not match the locked cryptography version")+ digest = hashlib.sha256(wheel.read_bytes()).hexdigest()+ first, remainder = block.split("\n", 1)+ replacement = f"{first}\n --hash=sha256:{digest} \\\n{remainder}"+ return lock.replace(block, replacement, 1)+++def run(argv: list[str], **kwargs) -> subprocess.CompletedProcess:+ return subprocess.run(+ argv, check=True, encoding="utf-8", creationflags=NO_WINDOW_CREATIONFLAGS, **kwargs+ )+++def main() -> int:+ if sys.platform != "darwin" or platform.machine().lower() not in {"x86_64", "amd64"}:+ print("Browser wheelhouse is only needed on Intel macOS")+ return 0+ assets = ROOT / "jarvis" / "assets" / "browser"+ lock = (assets / "requirements.lock").read_text(encoding="utf-8")+ wheels = assets / "wheels"+ wheels.mkdir(exist_ok=True)+ if list(wheels.glob("*.whl")):+ raise RuntimeError("Build the browser wheelhouse in a clean checkout")+ env = os.environ.copy()+ env["OPENSSL_STATIC"] = "1"+ env["OPENSSL_DIR"] = run(["brew", "--prefix", "openssl@3"], capture_output=True).stdout.strip()+ with tempfile.TemporaryDirectory(prefix="jarvis-browser-wheel-") as scratch:+ source = Path(scratch) / "source.lock"+ source.write_text(crypto_requirement(lock) + "\n", encoding="utf-8")+ run(+ [+ sys.executable,+ "-m",+ "pip",+ "wheel",+ "--no-deps",+ "--no-cache-dir",+ "--no-binary",+ "cryptography",+ "--require-hashes",+ "-r",+ str(source),+ "--wheel-dir",+ str(wheels),+ ],+ env=env,+ )+ built = list(wheels.glob("cryptography-*.whl"))+ if len(built) != 1:+ raise RuntimeError("Expected exactly one pinned cryptography wheel")+ # A wheel linked to Homebrew's shared OpenSSL works only on the builder.+ # Check the actual Mach-O dependencies before packaging the artifact.+ with zipfile.ZipFile(built[0]) as archive:+ binaries = [name for name in archive.namelist() if name.endswith(".so")]+ if not binaries:+ raise RuntimeError("Cryptography wheel has no native module")+ for name in binaries:+ binary = Path(scratch) / Path(name).name+ binary.write_bytes(archive.read(name))+ links = run(["otool", "-L", str(binary)], capture_output=True).stdout+ for line in links.splitlines()[1:]:+ dependency = line.strip().split(" ", 1)[0]+ if not dependency.startswith(("/usr/lib/", "/System/Library/")):+ raise RuntimeError("Cryptography wheel links a non-system shared library")+ (assets / "requirements-bundled.lock").write_text(+ add_wheel_hash(lock, built[0]), encoding="utf-8"+ )+ print(f"Bundled verified {built[0].name}")+ return 0+++if __name__ == "__main__":+ raise SystemExit(main())diff --git a/tests/unit/packaging/test_browser_wheelhouse.py b/tests/unit/packaging/test_browser_wheelhouse.pynew file mode 100644index 0000000000..b8c41a0591--- /dev/null+++ b/tests/unit/packaging/test_browser_wheelhouse.py@@ -0,0 +1,47 @@+"""A packaged native wheel remains tied to the source version and content hash."""++import hashlib++import pytest++from jarvis.society.browser import install+from scripts.prepare_browser_wheelhouse import add_wheel_hash+++def test_built_wheel_adds_its_digest_without_changing_other_pins(tmp_path):+ lock = "cryptography==50.0.1 \\\n --hash=sha256:upstream\nother==1.0\n"+ wheel = tmp_path / "cryptography-50.0.1-cp311-abi3-macosx_15_0_x86_64.whl"+ wheel.write_bytes(b"built native artifact")+ result = add_wheel_hash(lock, wheel)+ assert hashlib.sha256(wheel.read_bytes()).hexdigest() in result+ assert "--hash=sha256:upstream" in result+ assert result.endswith("other==1.0\n")+ assert result.count("cryptography==50.0.1") == 1+++def test_wheel_from_another_version_is_rejected(tmp_path):+ wheel = tmp_path / "cryptography-48.0.1-cp311-abi3-macosx_10_9_universal2.whl"+ wheel.write_bytes(b"wrong version")+ with pytest.raises(ValueError, match="locked cryptography version"):+ add_wheel_hash("cryptography==50.0.1 \\\n --hash=sha256:upstream\n", wheel)+++def test_only_frozen_app_uses_bundled_lock_and_wheelhouse(tmp_path, monkeypatch):+ module = tmp_path / "jarvis" / "society" / "browser" / "install.py"+ assets = tmp_path / "jarvis" / "assets" / "browser"+ assets.mkdir(parents=True)+ bundled = assets / "requirements-bundled.lock"+ bundled.write_text("cryptography==50.0.1", encoding="utf-8")+ (assets / "wheels").mkdir()+ monkeypatch.setattr(install, "__file__", str(module))+ monkeypatch.setattr(install.sys, "frozen", False, raising=False)+ assert install.requirements_path() == assets / "requirements.lock"+ assert install.bundled_wheel_args() == []+ monkeypatch.setattr(install.sys, "frozen", True)+ assert install.requirements_path() == bundled+ assert install.bundled_wheel_args() == [+ "--find-links",+ str(assets / "wheels"),+ "--only-binary",+ "cryptography",+ ]