Skip to content

armgit / avibe

Public Imported from GitHub
0

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.

fix(cli): avoid screenshot name races

cyhbde0c7578a58
diff --git a/tests/test_cli_screenshot_command.py b/tests/test_cli_screenshot_command.py
index 63a31aba6..214f09072 100644
--- a/tests/test_cli_screenshot_command.py
+++ b/tests/test_cli_screenshot_command.py
@@ -6,7 +6,7 @@ sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
import vibe.screenshot as screenshot
from vibe import cli
-from vibe.screenshot import ScreenshotError, ScreenshotResult, capture_screenshot
+from vibe.screenshot import ScreenshotError, ScreenshotResult, capture_screenshot, default_screenshot_path
def test_screenshot_parser_accepts_output_and_json() -> None:
@@ -80,6 +80,18 @@ def test_capture_screenshot_wraps_output_preparation_errors(tmp_path: Path) -> N
raise AssertionError("expected ScreenshotError")
+def test_default_screenshot_paths_are_unique(tmp_path: Path, monkeypatch) -> None:
+ monkeypatch.setattr(screenshot.paths, "get_vibe_remote_dir", lambda: tmp_path / ".vibe_remote")
+
+ first = default_screenshot_path()
+ second = default_screenshot_path()
+
+ assert first != second
+ assert first.parent == second.parent == tmp_path / ".vibe_remote" / "screenshots"
+ assert first.name.startswith("screenshot_")
+ assert first.suffix == ".png"
+
+
def test_capture_screenshot_preserves_existing_output_when_linux_backend_fails(
tmp_path: Path, monkeypatch
) -> None:
diff --git a/vibe/screenshot.py b/vibe/screenshot.py
index 9892b7a8d..2a310eaf9 100644
--- a/vibe/screenshot.py
+++ b/vibe/screenshot.py
@@ -2,10 +2,11 @@
from __future__ import annotations
-import subprocess
+import os
import sys
import tempfile
-import os
+import subprocess
+import uuid
from dataclasses import dataclass
from datetime import datetime
from pathlib import Path
@@ -29,14 +30,9 @@ def default_screenshot_dir() -> Path:
def default_screenshot_path() -> Path:
- timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
+ timestamp = datetime.now().strftime("%Y%m%d_%H%M%S_%f")
directory = default_screenshot_dir()
- candidate = directory / f"screenshot_{timestamp}.png"
- counter = 1
- while candidate.exists():
- candidate = directory / f"screenshot_{timestamp}_{counter}.png"
- counter += 1
- return candidate
+ return directory / f"screenshot_{timestamp}_{uuid.uuid4().hex[:8]}.png"
def capture_screenshot(output: str | Path | None = None) -> ScreenshotResult: