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.

feat(cli): add screenshot command

cyh509ee710d35f
diff --git a/README.md b/README.md
index f97215a4b..39fa43e5c 100644
--- a/README.md
+++ b/README.md
@@ -239,6 +239,7 @@ vibe # Start everything
vibe status # Check if running
vibe stop # Stop everything
vibe doctor # Diagnose issues
+vibe screenshot # Capture a local desktop screenshot
vibe task # Create and manage scheduled tasks
vibe hook # Queue one-shot async sends
```
diff --git a/README_ZH.md b/README_ZH.md
index c906db377..b799dfd5c 100644
--- a/README_ZH.md
+++ b/README_ZH.md
@@ -239,6 +239,7 @@ vibe # 启动一切
vibe status # 检查运行状态
vibe stop # 停止一切
vibe doctor # 诊断问题
+vibe screenshot # 截取本机桌面截图
vibe task # 创建和管理定时任务
vibe hook # 队列化一次性异步发送
```
diff --git a/docs/CLI.md b/docs/CLI.md
index 9b9455b12..504b8a65f 100644
--- a/docs/CLI.md
+++ b/docs/CLI.md
@@ -5,6 +5,7 @@
```bash
vibe # Start Vibe Remote (opens web UI)
vibe status # Check service status
+vibe screenshot # Capture a local desktop screenshot
vibe stop # Stop all services
```
@@ -117,6 +118,21 @@ vibe doctor
- Agent CLI availability (Claude Code, OpenCode, Codex)
- Runtime environment
+### `vibe screenshot`
+
+Capture the local desktop as a PNG file.
+
+```bash
+vibe screenshot
+vibe screenshot --output /tmp/screen.png
+vibe screenshot --json
+```
+
+**Behavior:**
+- Saves to `~/.vibe_remote/screenshots/` by default
+- Prints the saved file path, or a JSON payload with `--json`
+- Stays at the CLI layer only; it does not add IM commands, bot buttons, or agent prompt injection
+
### `vibe task`
Create, inspect, update, run, pause, resume, or remove scheduled tasks.
diff --git a/docs/CLI_ZH.md b/docs/CLI_ZH.md
index 195b5833f..9af5d7c30 100644
--- a/docs/CLI_ZH.md
+++ b/docs/CLI_ZH.md
@@ -5,6 +5,7 @@
```bash
vibe # 启动 Vibe Remote(打开 Web UI)
vibe status # 查看服务状态
+vibe screenshot # 截取本机桌面截图
vibe stop # 停止所有服务
```
@@ -117,6 +118,21 @@ vibe doctor
- Agent CLI 可用性(Claude Code、OpenCode、Codex)
- 运行时环境
+### `vibe screenshot`
+
+截取本机桌面并保存为 PNG 文件。
+
+```bash
+vibe screenshot
+vibe screenshot --output /tmp/screen.png
+vibe screenshot --json
+```
+
+**行为:**
+- 默认保存到 `~/.vibe_remote/screenshots/`
+- 默认输出保存路径;加 `--json` 时输出机器可读的 JSON
+- 只作为 CLI 层能力存在;不新增 IM 命令、bot 按钮,也不注入 Agent prompt
+
### `vibe task`
创建、查看、更新、立即执行、暂停、恢复或删除定时任务。
diff --git a/docs/COMMANDS.md b/docs/COMMANDS.md
index e2c9a3135..01d1ac2e0 100644
--- a/docs/COMMANDS.md
+++ b/docs/COMMANDS.md
@@ -522,6 +522,7 @@ The `vibe` executable controls the local service and async automation features.
| `vibe restart` | Stop then start again |
| `vibe status` | Print runtime status JSON |
| `vibe doctor` | Run diagnostics |
+| `vibe screenshot` | Capture a local desktop screenshot |
| `vibe version` | Show installed version |
| `vibe check-update` | Check for new version |
| `vibe upgrade` | Upgrade to latest version |
@@ -593,6 +594,20 @@ vibe doctor
- checks backend CLI availability
- checks runtime environment
+### `vibe screenshot`
+
+```bash
+vibe screenshot
+vibe screenshot --output /tmp/screen.png
+vibe screenshot --json
+```
+
+- captures the local desktop as a PNG file
+- saves to `~/.vibe_remote/screenshots/` by default
+- prints the saved file path by default
+- prints a machine-readable payload with `--json`
+- stays at the host CLI layer; it does not expose in-chat commands, bot buttons, or agent prompt injection
+
### `vibe version`
```bash
diff --git a/docs/COMMANDS_ZH.md b/docs/COMMANDS_ZH.md
index 9df322d08..b7ed03340 100644
--- a/docs/COMMANDS_ZH.md
+++ b/docs/COMMANDS_ZH.md
@@ -501,6 +501,7 @@ bind vr-a3x9k2
| `vibe restart` | 停止后重新启动 |
| `vibe status` | 输出运行状态 JSON |
| `vibe doctor` | 运行诊断 |
+| `vibe screenshot` | 截取本机桌面截图 |
| `vibe version` | 查看当前版本 |
| `vibe check-update` | 检查是否有新版本 |
| `vibe upgrade` | 升级到最新版 |
@@ -572,6 +573,20 @@ vibe doctor
- 检查 backend CLI 是否可用
- 检查运行环境
+### `vibe screenshot`
+
+```bash
+vibe screenshot
+vibe screenshot --output /tmp/screen.png
+vibe screenshot --json
+```
+
+- 截取本机桌面并保存为 PNG 文件
+- 默认保存到 `~/.vibe_remote/screenshots/`
+- 默认输出保存路径
+- 加 `--json` 时输出机器可读的 JSON
+- 只停留在宿主机 CLI 层;不新增聊天命令、bot 按钮,也不注入 Agent prompt
+
### `vibe version`
```bash
diff --git a/tests/test_cli_screenshot_command.py b/tests/test_cli_screenshot_command.py
new file mode 100644
index 000000000..baeddbf15
--- /dev/null
+++ b/tests/test_cli_screenshot_command.py
@@ -0,0 +1,67 @@
+import json
+import sys
+from pathlib import Path
+
+sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
+
+from vibe import cli
+from vibe.screenshot import ScreenshotError, ScreenshotResult
+
+
+def test_screenshot_parser_accepts_output_and_json() -> None:
+ parser = cli.build_parser()
+
+ args = parser.parse_args(["screenshot", "--output", "screen.png", "--json"])
+
+ assert args.command == "screenshot"
+ assert args.output == "screen.png"
+ assert args.json is True
+
+
+def test_cmd_screenshot_prints_path(capsys, monkeypatch) -> None:
+ captured: list[str | None] = []
+
+ def fake_capture(output=None):
+ captured.append(output)
+ return ScreenshotResult(path=Path("/tmp/vibe-screen.png"), backend="fake")
+
+ monkeypatch.setattr(cli, "capture_screenshot", fake_capture)
+ parser = cli.build_parser()
+ args = parser.parse_args(["screenshot", "--output", "custom.png"])
+
+ assert cli.cmd_screenshot(args) == 0
+ assert captured == ["custom.png"]
+ assert capsys.readouterr().out.strip() == "/tmp/vibe-screen.png"
+
+
+def test_cmd_screenshot_prints_json(capsys, monkeypatch) -> None:
+ monkeypatch.setattr(
+ cli,
+ "capture_screenshot",
+ lambda output=None: ScreenshotResult(path=Path("/tmp/vibe-screen.png"), backend="fake"),
+ )
+ parser = cli.build_parser()
+ args = parser.parse_args(["screenshot", "--json"])
+
+ assert cli.cmd_screenshot(args) == 0
+ payload = json.loads(capsys.readouterr().out)
+ assert payload == {
+ "ok": True,
+ "path": "/tmp/vibe-screen.png",
+ "backend": "fake",
+ }
+
+
+def test_cmd_screenshot_reports_errors(capsys, monkeypatch) -> None:
+ def fake_capture(output=None):
+ raise ScreenshotError("display is unavailable")
+
+ monkeypatch.setattr(cli, "capture_screenshot", fake_capture)
+ parser = cli.build_parser()
+ args = parser.parse_args(["screenshot", "--json"])
+
+ assert cli.cmd_screenshot(args) == 1
+ payload = json.loads(capsys.readouterr().err)
+ assert payload["ok"] is False
+ assert payload["code"] == "screenshot_failed"
+ assert payload["error"] == "display is unavailable"
diff --git a/vibe/cli.py b/vibe/cli.py
index 28695f63d..c020803ef 100644
--- a/vibe/cli.py
+++ b/vibe/cli.py
@@ -37,6 +37,7 @@ from core.watches import (
WatchRuntimeStateStore,
)
from vibe import __version__, api, runtime
+from vibe.screenshot import ScreenshotError, capture_screenshot
from vibe.upgrade import (
build_upgrade_plan,
cache_running_vibe_path,
@@ -1902,6 +1903,37 @@ def cmd_doctor():
return 0 if result["ok"] else 1
+def cmd_screenshot(args):
+ try:
+ result = capture_screenshot(getattr(args, "output", None))
+ except ScreenshotError as exc:
+ payload = {
+ "ok": False,
+ "code": "screenshot_failed",
+ "error": str(exc),
+ }
+ if getattr(args, "json", False):
+ print(json.dumps(payload, indent=2), file=sys.stderr)
+ else:
+ print(f"Screenshot failed: {exc}", file=sys.stderr)
+ return 1
+
+ if getattr(args, "json", False):
+ print(
+ json.dumps(
+ {
+ "ok": True,
+ "path": str(result.path),
+ "backend": result.backend,
+ },
+ indent=2,
+ )
+ )
+ else:
+ print(str(result.path))
+ return 0
+
+
def cmd_version():
"""Show current version."""
print(f"vibe-remote {__version__}")
@@ -2039,6 +2071,24 @@ def build_parser():
subparsers.add_parser("version", help="Show version")
subparsers.add_parser("check-update", help="Check for updates")
subparsers.add_parser("upgrade", help="Upgrade to latest version")
+ screenshot_parser = subparsers.add_parser(
+ "screenshot",
+ help="Capture a local desktop screenshot",
+ description=(
+ "Capture the local desktop as a PNG file. This is a CLI primitive; "
+ "it does not add IM commands, bot buttons, or agent prompt injection."
+ ),
+ )
+ screenshot_parser.add_argument(
+ "-o",
+ "--output",
+ help="PNG output path. Defaults to ~/.vibe_remote/screenshots/screenshot_<timestamp>.png.",
+ )
+ screenshot_parser.add_argument(
+ "--json",
+ action="store_true",
+ help="Print a machine-readable result with the output path and capture backend.",
+ )
task_parser = subparsers.add_parser(
"task",
@@ -2396,6 +2446,8 @@ def main():
sys.exit(cmd_status())
if args.command == "doctor":
sys.exit(cmd_doctor())
+ if args.command == "screenshot":
+ sys.exit(cmd_screenshot(args))
if args.command == "version":
sys.exit(cmd_version())
if args.command == "check-update":
diff --git a/vibe/screenshot.py b/vibe/screenshot.py
new file mode 100644
index 000000000..c875a38e7
--- /dev/null
+++ b/vibe/screenshot.py
@@ -0,0 +1,142 @@
+"""Local screenshot capture helpers for the Vibe Remote CLI."""
+
+from __future__ import annotations
+
+import subprocess
+import sys
+from dataclasses import dataclass
+from datetime import datetime
+from pathlib import Path
+from shutil import which
+
+from config import paths
+
+
+class ScreenshotError(RuntimeError):
+ """Raised when a local screenshot cannot be captured."""
+
+
+@dataclass(frozen=True)
+class ScreenshotResult:
+ path: Path
+ backend: str
+
+
+def default_screenshot_dir() -> Path:
+ return paths.get_vibe_remote_dir() / "screenshots"
+
+
+def default_screenshot_path() -> Path:
+ timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
+ 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
+
+
+def capture_screenshot(output: str | Path | None = None) -> ScreenshotResult:
+ """Capture the local desktop to a PNG file."""
+ output_path = _resolve_output_path(output)
+ output_path.parent.mkdir(parents=True, exist_ok=True)
+
+ if sys.platform == "darwin":
+ backend = _capture_macos(output_path)
+ elif sys.platform.startswith("win"):
+ backend = _capture_windows(output_path)
+ elif sys.platform.startswith("linux"):
+ backend = _capture_linux(output_path)
+ else:
+ raise ScreenshotError(f"screenshots are not supported on this platform: {sys.platform}")
+
+ _verify_output(output_path)
+ return ScreenshotResult(path=output_path, backend=backend)
+
+
+def _resolve_output_path(output: str | Path | None) -> Path:
+ path = Path(output).expanduser() if output else default_screenshot_path()
+ if not path.is_absolute():
+ path = Path.cwd() / path
+ if path.suffix.lower() != ".png":
+ path = path.with_suffix(".png")
+ return path.resolve()
+
+
+def _capture_macos(output: Path) -> str:
+ if which("screencapture") is None:
+ raise ScreenshotError("macOS screencapture command was not found")
+ _run_capture_command(["screencapture", "-x", str(output)], "screencapture")
+ return "screencapture"
+
+
+def _capture_windows(output: Path) -> str:
+ executable = which("powershell") or which("pwsh")
+ if executable is None:
+ raise ScreenshotError("PowerShell was not found")
+
+ script = r"""
+$ErrorActionPreference = 'Stop'
+Add-Type -AssemblyName System.Windows.Forms
+Add-Type -AssemblyName System.Drawing
+$path = $args[0]
+$bounds = [System.Windows.Forms.SystemInformation]::VirtualScreen
+$bitmap = New-Object System.Drawing.Bitmap $bounds.Width, $bounds.Height
+$graphics = [System.Drawing.Graphics]::FromImage($bitmap)
+$graphics.CopyFromScreen($bounds.Left, $bounds.Top, 0, 0, $bounds.Size)
+$bitmap.Save($path, [System.Drawing.Imaging.ImageFormat]::Png)
+$graphics.Dispose()
+$bitmap.Dispose()
+"""
+ _run_capture_command(
+ [executable, "-NoProfile", "-ExecutionPolicy", "Bypass", "-Command", script, str(output)],
+ "PowerShell screenshot capture",
+ )
+ return "powershell"
+
+
+def _capture_linux(output: Path) -> str:
+ candidates = [
+ ("grim", ["grim", str(output)]),
+ ("gnome-screenshot", ["gnome-screenshot", "-f", str(output)]),
+ ("spectacle", ["spectacle", "-b", "-n", "-o", str(output)]),
+ ("scrot", ["scrot", str(output)]),
+ ("import", ["import", "-window", "root", str(output)]),
+ ]
+ attempted: list[str] = []
+ for name, command in candidates:
+ if which(name) is None:
+ continue
+ attempted.append(name)
+ try:
+ _run_capture_command(command, name)
+ return name
+ except ScreenshotError:
+ if output.exists():
+ output.unlink()
+
+ if attempted:
+ raise ScreenshotError(f"installed screenshot tools failed: {', '.join(attempted)}")
+ raise ScreenshotError("no Linux screenshot tool found; install grim, gnome-screenshot, spectacle, scrot, or ImageMagick")
+
+
+def _run_capture_command(command: list[str], label: str) -> None:
+ try:
+ result = subprocess.run(command, capture_output=True, text=True, timeout=30)
+ except subprocess.TimeoutExpired as exc:
+ raise ScreenshotError(f"{label} timed out after {exc.timeout:g} seconds") from exc
+ if result.returncode == 0:
+ return
+ detail = (result.stderr or result.stdout or "").strip()
+ if detail:
+ raise ScreenshotError(f"{label} failed: {detail}")
+ raise ScreenshotError(f"{label} failed with exit code {result.returncode}")
+
+
+def _verify_output(output: Path) -> None:
+ if not output.is_file():
+ raise ScreenshotError(f"screenshot file was not created: {output}")
+ if output.stat().st_size <= 0:
+ output.unlink(missing_ok=True)
+ raise ScreenshotError("screenshot file was empty")