Make your computer a home for your AI partner. Avibe is the local-first Agent OS: Vibey, its built-in AI partner, works out of the box, and Claude Code, Codex & OpenCode run unchanged beside it — reach them from your browser, phone, or any chat app.
Python agentagent-osaiai-agentsai-partnerchatopsclaudeclaude-codecodexdevtoolsdiscord-botlark-botllmlocal-firstlong-term-memoryopencodeslack-botvibe-codingvibeywechat
feat(runtime): install the managed ripgrep on Windows (#2477)
Call White0af1f206c7c5
diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.ymlindex 2c3aab307..0883452a6 100644--- a/.github/workflows/lint.yml+++ b/.github/workflows/lint.yml@@ -631,3 +631,13 @@ jobs:python -m pytest -q -ratests/test_process_isolation.py tests/test_model_hub_l3.py tests/test_model_hub_migration_review_boundaries.py-k "console_window or cannot_be_bound or byte_for_byte"++ # ripgrep's Windows release is a zip, which only this managed runtime+ # extracts: install the bytes the manifest pins for this machine from a+ # copy of upstream's archive, and run them.+ - name: Verify the managed ripgrep installs from its Windows zip+ shell: pwsh+ run: |+ $env:AVIBE_TEST_RIPGREP_ZIPS = Join-Path $env:RUNNER_TEMP "ripgrep-zips"+ python -c "import json, os, pathlib, urllib.request; target = pathlib.Path(os.environ['AVIBE_TEST_RIPGREP_ZIPS']); target.mkdir(exist_ok=True); archives = json.load(open('vibe/ripgrep_runtime_manifest.json'))['archives']; [urllib.request.urlretrieve(entry['url'], target / entry['name']) for tag, entry in archives.items() if tag.startswith('win32-')]"+ python -m pytest -q -ra tests/test_ripgrep_runtime.py -k "pinned_windows_zip or six_platform or zip_entry"diff --git a/core/managed_runtime.py b/core/managed_runtime.pyindex e5bfde395..d85ff6797 100644--- a/core/managed_runtime.py+++ b/core/managed_runtime.py@@ -17,6 +17,7 @@ import threadingimport timeimport urllib.parseimport urllib.request+import zipfilefrom collections.abc import Callable, Mappingfrom dataclasses import dataclassfrom pathlib import Path, PurePosixPath, PureWindowsPath@@ -125,7 +126,8 @@ class ManagedRuntimeArchive:binary_sha256: str | Nonesize: int | Nonebin_path: str- # One of ARCHIVE_FORMATS; ``binary`` means the asset is the executable itself.+ # One of ARCHIVE_FORMATS; ``binary`` means the asset is the executable itself, ``zip`` is what+ # upstream projects publish for Windows.format: str = "tar.gz"@@ -2285,7 +2287,7 @@ def install_lock_for(runtime_id: str) -> threading.Lock:return _INSTALL_LOCKS.setdefault(runtime_id, threading.Lock())-ARCHIVE_FORMATS = frozenset({"tar.gz", "binary"})+ARCHIVE_FORMATS = frozenset({"tar.gz", "zip", "binary"})def stage_archive(archive_path: Path, archive_format: str, staging_dir: Path, *, bin_path: str) -> None:@@ -2299,6 +2301,9 @@ def stage_archive(archive_path: Path, archive_format: str, staging_dir: Path, *,if archive_format == "tar.gz":with tarfile.open(archive_path, "r:gz") as archive_file:safe_extract_tar(archive_file, staging_dir)+ elif archive_format == "zip":+ with zipfile.ZipFile(archive_path) as archive_file:+ safe_extract_zip(archive_file, staging_dir)elif archive_format == "binary":target = staging_dir / bin_pathtarget.parent.mkdir(parents=True, exist_ok=True)@@ -2307,6 +2312,37 @@ def stage_archive(archive_path: Path, archive_format: str, staging_dir: Path, *,raise ValueError(f"unsupported archive format: {archive_format}")+def safe_extract_zip(archive: zipfile.ZipFile, destination: Path) -> None:+ """Extract a zip of regular files and directories into ``destination``, refusing what ``safe_extract_tar``+ refuses: a path that leaves ``destination`` and a link (a zip records a symlink as a Unix file mode).++ Each member is written to the path checked here, never one ``zipfile`` derives itself: on Windows it+ strips trailing spaces and periods from a name's parts, as Windows itself does, so ``.. /x`` would+ become ``../x``. A part ending in either is refused for that reason.+ """+ destination_resolved = destination.resolve()+ planned: list[tuple[zipfile.ZipInfo, Path]] = []+ for member in archive.infolist():+ name = member.filename.replace("\\", "/")+ parts = PurePosixPath(name).parts+ if archive_path_is_unsafe(member.filename) or any(part != part.rstrip(" .") for part in parts):+ raise ValueError(f"Unsafe managed runtime archive path: {member.filename}")+ target = destination.joinpath(*parts).resolve()+ if target != destination_resolved and destination_resolved not in target.parents:+ raise ValueError(f"Unsafe managed runtime archive path: {member.filename}")+ # A zip need not record a file type; only a type that is neither a file nor a directory is refused.+ if stat.S_IFMT(member.external_attr >> 16) not in (0, stat.S_IFREG, stat.S_IFDIR):+ raise ValueError(f"Unsupported managed runtime archive member: {member.filename}")+ planned.append((member, target))+ for member, target in planned:+ if member.is_dir():+ target.mkdir(parents=True, exist_ok=True)+ continue+ target.parent.mkdir(parents=True, exist_ok=True)+ with archive.open(member) as source, open(target, "wb") as sink:+ shutil.copyfileobj(source, sink)++def safe_extract_tar(archive: tarfile.TarFile, destination: Path) -> None:supports_data_filter = hasattr(tarfile, "data_filter")destination_resolved = destination.resolve()diff --git a/core/ripgrep_runtime.py b/core/ripgrep_runtime.pyindex 7a3a20c20..038f6bde4 100644--- a/core/ripgrep_runtime.py+++ b/core/ripgrep_runtime.py@@ -76,7 +76,8 @@ def _probe_ripgrep_version(binary: Path | None) -> str | None:text=True,timeout=5,check=False,- **isolated_subprocess_kwargs(),+ # Run while a status path resolves ripgrep, often under a service with no console of its own.+ **isolated_subprocess_kwargs(console=False),)except Exception: # noqa: BLE001return Nonediff --git a/docs/plans/ripgrep-runtime.md b/docs/plans/ripgrep-runtime.mdindex 10c4f1d52..11035daa4 100644--- a/docs/plans/ripgrep-runtime.md+++ b/docs/plans/ripgrep-runtime.md@@ -44,12 +44,13 @@ digests, which the mirror requires.## Scope-- The platforms are darwin and linux on arm64 and x64, as for the Git runtime.- Windows reports `ripgrep_platform_unsupported` for these reasons:- - The managed-runtime core extracts only `.tar.gz`, and upstream ships a- Windows `.zip`.- - Vibey's job host does not run commands on Windows.- - The Codex, Claude Code, and OpenCode CLIs bundle their own ripgrep.+- The platforms are darwin, linux, and Windows on arm64 and x64. On Windows the+ manifest pins upstream's `.zip` (`"format": "zip"`, extracted by the+ managed-runtime core with the same path and link checks as a `.tar.gz`), and+ the binary is `rg.exe`. ripgrep matters more there than elsewhere: Windows+ has no `grep`, `find` is a different program, and `Select-String` is slow, so+ with `rg` on the Agent PATH Vibey's prompt names it. The Codex, Claude Code,+ and OpenCode CLIs bundle their own ripgrep.- ripgrep is not a `vibe doctor` dependency or repair target. Its absence onlychanges the prompt line, and `vibe runtime prepare` installs it again.- To move to a newer ripgrep, update the manifest. The mirror then adds the newdiff --git a/tests/test_cloudflared_runtime.py b/tests/test_cloudflared_runtime.pyindex d625e5793..41a21949d 100644--- a/tests/test_cloudflared_runtime.py+++ b/tests/test_cloudflared_runtime.py@@ -101,7 +101,7 @@ def test_raw_binary_asset_installs_verified_at_its_bin_path(tmp_path: Path, monk("override", "reason"),[({"binary_sha256": "0" * 64}, "cloudflared_binary_checksum_mismatch"),- ({"format": "zip"}, "cloudflared_manifest_invalid"),+ ({"format": "tar.xz"}, "cloudflared_manifest_invalid"),],)def test_unverifiable_or_unknown_assets_do_not_install(diff --git a/tests/test_ripgrep_runtime.py b/tests/test_ripgrep_runtime.pyindex 95866986e..d7bf2ab71 100644--- a/tests/test_ripgrep_runtime.py+++ b/tests/test_ripgrep_runtime.py@@ -5,7 +5,9 @@ import jsonimport osimport reimport stat+import subprocessimport tarfile+import zipfilefrom pathlib import Pathimport pytest@@ -17,7 +19,9 @@ from core.ripgrep_runtime import RipgrepRuntimeManager, prepend_managed_ripgrep_UPSTREAM = "https://github.com/BurntSushi/ripgrep/releases/download"-def pin_test_ripgrep(tmp_path: Path, monkeypatch: pytest.MonkeyPatch, *, tamper: str | None = None) -> None:+def pin_test_ripgrep(+ tmp_path: Path, monkeypatch: pytest.MonkeyPatch, *, tamper: str | None = None, archive_format: str = "tar.gz"+) -> None:"""Pin a stand-in ``rg`` archive in a test manifest the default manager also reads."""stem = "ripgrep-15.2.0-test"@@ -25,9 +29,13 @@ def pin_test_ripgrep(tmp_path: Path, monkeypatch: pytest.MonkeyPatch, *, tamper:binary.parent.mkdir(parents=True)binary.write_text('#!/bin/sh\necho "ripgrep 15.2.0 (rev test)"\n', encoding="utf-8")binary.chmod(binary.stat().st_mode | stat.S_IXUSR)- archive = tmp_path / f"{stem}.tar.gz"- with tarfile.open(archive, "w:gz") as tar:- tar.add(binary, arcname=f"{stem}/rg")+ archive = tmp_path / f"{stem}.{archive_format}"+ if archive_format == "zip":+ with zipfile.ZipFile(archive, "w") as zipped:+ zipped.write(binary, arcname=f"{stem}/rg")+ else:+ with tarfile.open(archive, "w:gz") as tar:+ tar.add(binary, arcname=f"{stem}/rg")entry = {"name": archive.name,"url": archive.as_uri(),@@ -35,6 +43,7 @@ def pin_test_ripgrep(tmp_path: Path, monkeypatch: pytest.MonkeyPatch, *, tamper:"binary_sha256": hashlib.sha256(binary.read_bytes()).hexdigest(),"size": archive.stat().st_size,"bin_path": f"{stem}/rg",+ "format": archive_format,}if tamper is not None:entry[tamper] = "0" * 64@@ -55,14 +64,16 @@ def pin_test_ripgrep(tmp_path: Path, monkeypatch: pytest.MonkeyPatch, *, tamper:monkeypatch.setenv("VIBE_RIPGREP_MANIFEST_PATH", str(manifest))-def install_test_ripgrep(tmp_path: Path, monkeypatch: pytest.MonkeyPatch, *, tamper: str | None = None) -> dict:+def install_test_ripgrep(+ tmp_path: Path, monkeypatch: pytest.MonkeyPatch, *, tamper: str | None = None, archive_format: str = "tar.gz"+) -> dict:"""Install a stand-in ``rg`` through a test manifest the default manager also reads."""- pin_test_ripgrep(tmp_path, monkeypatch, tamper=tamper)+ pin_test_ripgrep(tmp_path, monkeypatch, tamper=tamper, archive_format=archive_format)return RipgrepRuntimeManager().ensure()-def test_packaged_manifest_pins_the_official_four_platform_release(tmp_path: Path) -> None:+def test_packaged_manifest_pins_the_official_six_platform_release(tmp_path: Path) -> None:manifest = RipgrepRuntimeManager(runtime_dir=tmp_path / "runtime", offline=True)._load_manifest(allow_network=False)@@ -74,18 +85,23 @@ def test_packaged_manifest_pins_the_official_four_platform_release(tmp_path: Pat"darwin-x64": "x86_64-apple-darwin","linux-arm64": "aarch64-unknown-linux-musl","linux-x64": "x86_64-unknown-linux-musl",+ "win32-arm64": "aarch64-pc-windows-msvc",+ "win32-x64": "x86_64-pc-windows-msvc",}assert set(manifest.archives) == set(targets)for platform_tag, archive in manifest.archives.items():stem = f"ripgrep-15.2.0-{targets[platform_tag]}"- assert archive.name == f"{stem}.tar.gz"+ windows = platform_tag.startswith("win32-")+ assert (archive.name, archive.format) == ((f"{stem}.zip", "zip") if windows else (f"{stem}.tar.gz", "tar.gz"))assert archive.url == f"{UPSTREAM}/15.2.0/{archive.name}"- assert archive.bin_path == f"{stem}/rg"+ assert archive.bin_path == f"{stem}/{'rg.exe' if windows else 'rg'}"assert archive.size is not None and archive.size > 0assert re.fullmatch(r"[0-9a-f]{64}", archive.sha256)assert re.fullmatch(r"[0-9a-f]{64}", archive.binary_sha256 or "")[email protected](os.name == "nt", reason="the stand-in rg is a shell script")[email protected]("archive_format", ("tar.gz", "zip"))@pytest.mark.parametrize(("tamper", "reason"),(@@ -95,9 +111,9 @@ def test_packaged_manifest_pins_the_official_four_platform_release(tmp_path: Pat),)def test_install_accepts_only_the_bytes_the_manifest_pins(- tmp_path: Path, monkeypatch: pytest.MonkeyPatch, tamper: str | None, reason: str | None+ tmp_path: Path, monkeypatch: pytest.MonkeyPatch, tamper: str | None, reason: str | None, archive_format: str) -> None:- result = install_test_ripgrep(tmp_path, monkeypatch, tamper=tamper)+ result = install_test_ripgrep(tmp_path, monkeypatch, tamper=tamper, archive_format=archive_format)assert result.get("reason") == reasonresolved = RipgrepRuntimeManager().resolve_binary()@@ -184,3 +200,72 @@ def test_startup_reconcile_installs_ripgrep_without_failing_startup(assert resolved is None# A missing ripgrep only changes Vibey's prompt line, so it never fails startup.assert out["ok"] is True+++ "member",+ ("../escape", "/absolute", "C:/drive", "inside/../../escape", ".. /escape", "inside/name.", "link"),+)+def test_a_zip_entry_that_leaves_the_runtime_or_links_out_is_refused(tmp_path: Path, member: str) -> None:+ """The same rules ``safe_extract_tar`` applies: nothing lands outside the staging directory, and no links."""+ archive = tmp_path / "archive.zip"+ with zipfile.ZipFile(archive, "w") as zipped:+ if member == "link":+ info = zipfile.ZipInfo("runtime/rg")+ info.external_attr = (stat.S_IFLNK | 0o777) << 16+ zipped.writestr(info, "/etc/passwd")+ else:+ zipped.writestr(zipfile.ZipInfo(member), "x")+ staging = tmp_path / "staging"+ staging.mkdir()++ with pytest.raises(ValueError):+ managed_runtime.stage_archive(archive, "zip", staging, bin_path="runtime/rg")++ assert list(staging.iterdir()) == []+ assert not (tmp_path / "escape").exists()+++ not os.environ.get("AVIBE_TEST_RIPGREP_ZIPS"),+ reason="needs ripgrep's Windows zips downloaded into AVIBE_TEST_RIPGREP_ZIPS (CI's Windows jobs)",+)+def test_the_pinned_windows_zip_installs_and_runs(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:+ """The bytes the packaged manifest pins for this Windows machine, from a local copy of upstream's zip."""+ packaged = RipgrepRuntimeManager(runtime_dir=tmp_path / "runtime", offline=True)._load_manifest(+ allow_network=False+ )+ tag = managed_runtime.runtime_platform_tag()+ payload = json.loads(json.dumps(packaged.payload))+ entry = payload["archives"][tag]+ entry["url"] = (Path(os.environ["AVIBE_TEST_RIPGREP_ZIPS"]) / entry["name"]).as_uri()+ manifest = tmp_path / "ripgrep_runtime_manifest.json"+ manifest.write_text(json.dumps(payload), encoding="utf-8")+ monkeypatch.setenv("VIBE_RIPGREP_MANIFEST_PATH", str(manifest))++ result = RipgrepRuntimeManager().ensure()++ assert result["ok"] is True and result["version"] == "15.2.0"+ binary = RipgrepRuntimeManager().resolve_binary()+ assert binary is not None and binary.name == "rg.exe"+ version = subprocess.run([str(binary), "--version"], capture_output=True, text=True, timeout=30, check=True)+ assert version.stdout.startswith("ripgrep 15.2.0")+ env: dict[str, str] = {"PATH": os.environ.get("SystemRoot", r"C:\Windows")}+ assert prepend_managed_ripgrep_to_path(env, base_env={}) is True+ assert env["PATH"].split(os.pathsep)[0] == str(binary.parent)+++def test_a_zip_that_records_no_file_types_extracts(tmp_path: Path) -> None:+ """A zip need not record a Unix file type: ``writestr`` gives a file a bare permission mode."""+ archive = tmp_path / "archive.zip"+ with zipfile.ZipFile(archive, "w") as zipped:+ zipped.writestr("runtime/", "")+ info = zipfile.ZipInfo("runtime/rg")+ info.external_attr = 0o600 << 16+ zipped.writestr(info, "binary")+ staging = tmp_path / "staging"+ staging.mkdir()++ managed_runtime.stage_archive(archive, "zip", staging, bin_path="runtime/rg")++ assert (staging / "runtime" / "rg").read_text(encoding="utf-8") == "binary"diff --git a/vibe/ripgrep_runtime_manifest.json b/vibe/ripgrep_runtime_manifest.jsonindex 04b77e1a5..278efed7b 100644--- a/vibe/ripgrep_runtime_manifest.json+++ b/vibe/ripgrep_runtime_manifest.json@@ -36,6 +36,24 @@"binary_sha256": "e62198eb19b136b88c330af83647b5a962cb99b6b1f066758568f12de1974849","size": 2265718,"bin_path": "ripgrep-15.2.0-x86_64-unknown-linux-musl/rg"+ },+ "win32-arm64": {+ "name": "ripgrep-15.2.0-aarch64-pc-windows-msvc.zip",+ "url": "https://github.com/BurntSushi/ripgrep/releases/download/15.2.0/ripgrep-15.2.0-aarch64-pc-windows-msvc.zip",+ "sha256": "e4abca10c3a64ebea742667dd7009449d49403db5460dd6873e389fa2945360f",+ "binary_sha256": "d33a29a9ef03c9f4c03be9e8d88498e6e2d2e566d64cdbdef97f9afc8f13120c",+ "size": 1640124,+ "bin_path": "ripgrep-15.2.0-aarch64-pc-windows-msvc/rg.exe",+ "format": "zip"+ },+ "win32-x64": {+ "name": "ripgrep-15.2.0-x86_64-pc-windows-msvc.zip",+ "url": "https://github.com/BurntSushi/ripgrep/releases/download/15.2.0/ripgrep-15.2.0-x86_64-pc-windows-msvc.zip",+ "sha256": "71b2fef860abe467217a538ff31de02f5258807c0129f771846f87bd029aafc5",+ "binary_sha256": "14231169855ec5205cf5a1b6f1db358ff4aed4247c86b69ce8aae647c77f6680",+ "size": 1789611,+ "bin_path": "ripgrep-15.2.0-x86_64-pc-windows-msvc/rg.exe",+ "format": "zip"}}}