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
fix(cli): keep bare vibe restart compatible
cyh3ee2d2aa34eb
diff --git a/docs/CLI.md b/docs/CLI.mdindex 4e18309fa..70c200a4e 100644--- a/docs/CLI.md+++ b/docs/CLI.md@@ -3,7 +3,8 @@## Quick Start```bash-vibe # Start Vibe Remote (opens web UI)+vibe # Restart Vibe Remote during the compatibility window+vibe start # Start Vibe Remote if needed (opens web UI)vibe status # Check service statusvibe restart # Restart all services (use --delay-seconds when agent-triggered)vibe remote # Guided Vibe Cloud remote-access setup@@ -28,14 +29,27 @@ The command walks you through signing in at `https://avibe.bot`, creating a remo### `vibe`-Start Vibe Remote if needed. Opens the web UI in your browser.+Compatibility default: restart Vibe Remote, then open the web UI in your browser.```bashvibe```**Behavior:**-- Reuses the main service if it is already running+- Stops and restarts the main service and Web UI+- Terminates the OpenCode server as part of the restart+- Kept as restart-compatible during the migration window. Use `vibe start` when you want ensure-start behavior without stopping running processes.++### `vibe start`++Start Vibe Remote if needed. Opens the web UI in your browser.++```bash+vibe start+```++**Behavior:**+- Reuses the main service and Web UI if they are already running- Opens the setup wizard at `http://127.0.0.1:5123`- **Preserves running processes** — Use `vibe restart` when you need an explicit restart@@ -247,6 +261,8 @@ The key difference between commands:| Command | Main Service | OpenCode Server ||---------|--------------|-----------------|+| `vibe start` | Start/reuse | Preserved |+| `vibe` | Restart | **Terminated** || `vibe restart` | Restart | **Terminated** || `vibe stop` | Stop | **Terminated** |@@ -323,7 +339,7 @@ The web UI (`http://127.0.0.1:5123`) provides the same controls:| Button | Equivalent CLI | OpenCode Behavior ||--------|---------------|-------------------|-| **Start** | `vibe` | Starts on demand |+| **Start** | `vibe start` | Starts on demand || **Restart** | `vibe restart` | Terminated || **Stop** | `vibe stop` | Terminated |diff --git a/docs/CLI_ZH.md b/docs/CLI_ZH.mdindex 8050c9297..17e9b3fdc 100644--- a/docs/CLI_ZH.md+++ b/docs/CLI_ZH.md@@ -3,7 +3,8 @@## 快速开始```bash-vibe # 启动 Vibe Remote(打开 Web UI)+vibe # 兼容期内重启 Vibe Remote+vibe start # 按需启动 Vibe Remote(打开 Web UI)vibe status # 查看服务状态vibe remote # 引导式配置 Vibe Cloud 远程访问vibe screenshot # 截取本机桌面截图@@ -27,14 +28,27 @@ vibe remote### `vibe`-按需启动 Vibe Remote。会在浏览器中打开 Web UI。+兼容期默认重启 Vibe Remote,然后在浏览器中打开 Web UI。```bashvibe```**行为:**-- 如果主服务已在运行,则复用现有进程+- 停止并重启主服务与 Web UI+- 重启过程中会终止 OpenCode 服务器+- 为兼容旧版本升级流程,裸 `vibe` 暂时保持重启语义;如果只想按需启动并保留现有进程,请使用 `vibe start`++### `vibe start`++按需启动 Vibe Remote。会在浏览器中打开 Web UI。++```bash+vibe start+```++**行为:**+- 如果主服务与 Web UI 已在运行,则复用现有进程- 打开设置向导 `http://127.0.0.1:5123`- **保留已运行的进程** — 需要明确重启时请使用 `vibe restart`@@ -197,6 +211,8 @@ Vibe Remote 管理两类进程:| 命令 | 主服务 | OpenCode 服务器 ||------|--------|-----------------|+| `vibe start` | 启动/复用 | 保留 |+| `vibe` | 重启 | **终止** || `vibe restart` | 重启 | **终止** || `vibe stop` | 停止 | **终止** |@@ -273,7 +289,7 @@ Web UI (`http://127.0.0.1:5123`) 提供相同的控制功能:| 按钮 | 等效 CLI | OpenCode 行为 ||------|---------|---------------|-| **Start** | `vibe` | 按需启动 |+| **Start** | `vibe start` | 按需启动 || **Restart** | `vibe restart` | 终止 || **Stop** | `vibe stop` | 终止 |diff --git a/docs/COMMANDS.md b/docs/COMMANDS.mdindex 4396a5ca3..ccd8b3987 100644--- a/docs/COMMANDS.md+++ b/docs/COMMANDS.md@@ -517,7 +517,8 @@ The `vibe` executable controls the local service and async automation features.| Command | Purpose || --- | --- |-| `vibe` | Start the service and Web UI if needed; reuse already-running processes |+| `vibe` | Compatibility default: restart the service and Web UI |+| `vibe start` | Start the service and Web UI if needed; reuse already-running processes || `vibe stop` | Stop the service and UI; also terminates OpenCode server || `vibe restart` | Stop then start again || `vibe status` | Print runtime status JSON |@@ -536,6 +537,16 @@ The `vibe` executable controls the local service and async automation features.vibe```+- compatibility default during the migration window: stops then starts Vibe Remote+- terminates the OpenCode server as part of the restart+- use `vibe start` for ensure-start behavior without stopping running processes++### `vibe start`++```bash+vibe start+```+- starts the main service if it is not already running- opens the Web UI- preserves already-running service, Web UI, and OpenCode processes; use `vibe restart` for an explicit restartdiff --git a/docs/COMMANDS_ZH.md b/docs/COMMANDS_ZH.mdindex ccf9ad5ec..da0c93c23 100644--- a/docs/COMMANDS_ZH.md+++ b/docs/COMMANDS_ZH.md@@ -496,7 +496,8 @@ bind vr-a3x9k2| 命令 | 作用 || --- | --- |-| `vibe` | 按需启动服务与 Web UI;已运行时复用现有进程 |+| `vibe` | 兼容期默认重启服务与 Web UI |+| `vibe start` | 按需启动服务与 Web UI;已运行时复用现有进程 || `vibe stop` | 停止服务与 UI,同时终止 OpenCode server || `vibe restart` | 停止后重新启动 || `vibe status` | 输出运行状态 JSON |@@ -515,6 +516,16 @@ bind vr-a3x9k2vibe```+- 兼容期默认停止并重新启动 Vibe Remote+- 重启过程中会终止 OpenCode server+- 如果需要不停止现有进程的 ensure-start 行为,请使用 `vibe start`++### `vibe start`++```bash+vibe start+```+- 如果主服务尚未运行,则启动主服务- 打开 Web UI- 保留已运行的服务、Web UI 与 OpenCode server;需要明确重启时使用 `vibe restart`diff --git a/tests/test_runtime_service_lock.py b/tests/test_runtime_service_lock.pyindex 0e19c4cae..e6c4d1a7e 100644--- a/tests/test_runtime_service_lock.py+++ b/tests/test_runtime_service_lock.py@@ -1,9 +1,7 @@-import osimport sysimport tempfileimport unittestfrom pathlib import Path-from types import SimpleNamespacefrom unittest.mock import patchsys.path.insert(0, str(Path(__file__).resolve().parents[1]))@@ -11,10 +9,6 @@ sys.path.insert(0, str(Path(__file__).resolve().parents[1]))from vibe import runtime-def subprocess_result(stdout: str = "", returncode: int = 0):- return SimpleNamespace(stdout=stdout, returncode=returncode)--class RuntimeServiceLockTests(unittest.TestCase):def test_start_service_reuses_existing_live_pid(self):with tempfile.TemporaryDirectory() as tmpdir:@@ -66,81 +60,5 @@ class RuntimeServiceLockTests(unittest.TestCase):self.assertEqual(pid, 12345)spawn_background.assert_not_called()- def test_runtime_processes_stale_when_service_predates_installed_package(self):- with tempfile.TemporaryDirectory() as tmpdir:- root = Path(tmpdir)- pid_path = root / "service.pid"- ui_pid_path = root / "ui.pid"- package_root = root / "site-packages" / "vibe"- project_root = root / "site-packages"- package_root.mkdir(parents=True)- init_path = package_root / "__init__.py"- service_main = package_root / "service_main.py"- ui_server = package_root / "ui_server.py"- for marker in (init_path, service_main, ui_server):- marker.write_text("", encoding="utf-8")- os.utime(marker, (2000, 2000))- pid_path.write_text("12345", encoding="utf-8")-- with patch("vibe.runtime.paths.get_runtime_pid_path", return_value=pid_path):- with patch("vibe.runtime.paths.get_runtime_ui_pid_path", return_value=ui_pid_path):- with patch("vibe.runtime.get_project_root", return_value=project_root):- with patch("vibe.runtime.get_package_root", return_value=package_root):- with patch("vibe.runtime.get_service_main_path", return_value=service_main):- with patch("vibe.runtime.pid_alive", return_value=True):- with patch(- "vibe.runtime.get_process_command",- return_value=f"{sys.executable} {service_main}",- ):- with patch("vibe.runtime.get_process_start_time", return_value=1000.0):- self.assertTrue(runtime.runtime_processes_stale_after_package_update())-- def test_runtime_process_stale_check_is_disabled_in_source_checkout(self):- with tempfile.TemporaryDirectory() as tmpdir:- root = Path(tmpdir)- pid_path = root / "service.pid"- ui_pid_path = root / "ui.pid"- project_root = root / "checkout"- package_root = project_root / "vibe"- package_root.mkdir(parents=True)- (project_root / "main.py").write_text("", encoding="utf-8")- service_main = project_root / "main.py"- (package_root / "__init__.py").write_text("", encoding="utf-8")- (package_root / "ui_server.py").write_text("", encoding="utf-8")- pid_path.write_text("12345", encoding="utf-8")-- with patch("vibe.runtime.paths.get_runtime_pid_path", return_value=pid_path):- with patch("vibe.runtime.paths.get_runtime_ui_pid_path", return_value=ui_pid_path):- with patch("vibe.runtime.get_project_root", return_value=project_root):- with patch("vibe.runtime.get_package_root", return_value=package_root):- with patch("vibe.runtime.get_service_main_path", return_value=service_main):- with patch("vibe.runtime.pid_alive", return_value=True):- with patch(- "vibe.runtime.get_process_command",- return_value=f"{sys.executable} {service_main}",- ):- with patch("vibe.runtime.get_process_start_time", return_value=1000.0):- self.assertFalse(runtime.runtime_processes_stale_after_package_update())-- def test_parse_ps_elapsed_seconds(self):- self.assertEqual(runtime._parse_ps_elapsed_seconds("00:07"), 7)- self.assertEqual(runtime._parse_ps_elapsed_seconds("01:02:03"), 3723)- self.assertEqual(runtime._parse_ps_elapsed_seconds("2-01:02:03"), 176523)- self.assertIsNone(runtime._parse_ps_elapsed_seconds("Wed May 13 12:00:00 2026"))-- def test_ps_process_start_time_uses_locale_independent_elapsed_time(self):- completed = subprocess_result(stdout="01:02:03\n", returncode=0)- with patch("vibe.runtime.subprocess.run", return_value=completed) as run:- with patch("vibe.runtime.time.time", return_value=10_000.0):- self.assertEqual(runtime._ps_process_start_time(12345), 6277.0)- run.assert_called_once_with(- ["ps", "-p", "12345", "-o", "etime="],- capture_output=True,- text=True,- timeout=2,- check=False,- )--if __name__ == "__main__":unittest.main()diff --git a/tests/test_vibe_cli.py b/tests/test_vibe_cli.pyindex d85606554..51b5dc657 100644--- a/tests/test_vibe_cli.py+++ b/tests/test_vibe_cli.py@@ -169,14 +169,24 @@ def test_cmd_restart_runs_synchronously_by_default(monkeypatch):calls = []monkeypatch.setattr(cli, "cmd_stop", lambda: calls.append("stop") or 0)- monkeypatch.setattr(cli, "cmd_vibe", lambda: calls.append("start") or 0)+ monkeypatch.setattr(cli, "cmd_start", lambda: calls.append("start") or 0)monkeypatch.setattr(cli.time, "sleep", lambda seconds: calls.append(("sleep", seconds)))assert cli._cmd_restart_with_delay(0) == 0assert calls == ["stop", ("sleep", 3), "start"]-def test_cmd_vibe_restarts_stale_runtime_processes(monkeypatch):+def test_cmd_vibe_uses_restart_compatibility_default(monkeypatch):+ calls = []++ monkeypatch.setattr(cli, "_cmd_restart_with_delay", lambda delay: calls.append(("restart", delay)) or 0)++ assert cli.cmd_vibe() == 0++ assert calls == [("restart", 0.0)]+++def test_cmd_start_ensures_services_without_stopping(monkeypatch):calls = []config = SimpleNamespace(has_configured_platform_credentials=lambda: True,@@ -185,12 +195,17 @@ def test_cmd_vibe_restarts_stale_runtime_processes(monkeypatch):monkeypatch.setattr(cli.paths, "ensure_data_dirs", lambda: None)monkeypatch.setattr(cli, "_ensure_config", lambda: config)- monkeypatch.setattr(cli.runtime, "runtime_processes_stale_after_package_update", lambda: True)- monkeypatch.setattr(cli, "_cmd_restart_with_delay", lambda delay: calls.append(("restart", delay)) or 0)+ monkeypatch.setattr(cli, "_write_status", lambda *args, **kwargs: calls.append(("status", args)))+ monkeypatch.setattr(cli.runtime, "start_service", lambda: calls.append("start_service") or 1234)+ monkeypatch.setattr(cli.runtime, "effective_ui_bind_host", lambda cfg: "127.0.0.1")+ monkeypatch.setattr(cli.runtime, "start_ui", lambda host, port: calls.append(("start_ui", host, port)) or 5678)+ monkeypatch.setattr(cli.runtime, "write_status", lambda *args: calls.append(("runtime_status", args)))- assert cli.cmd_vibe() == 0+ assert cli.cmd_start() == 0- assert calls == [("restart", 0.0)]+ assert "start_service" in calls+ assert ("start_ui", "127.0.0.1", 5123) in calls+ assert not any(call == "stop" for call in calls)def test_restart_parser_accepts_delay_seconds():@@ -201,6 +216,13 @@ def test_restart_parser_accepts_delay_seconds():assert args.delay_seconds == 60+def test_start_parser_accepts_start_command():+ parser = cli.build_parser()+ args = parser.parse_args(["start"])++ assert args.command == "start"++def test_remote_parser_accepts_pairing_command():parser = cli.build_parser()args = parser.parse_args(["remote", "pair", "vrp_test", "--device-name", "Mac Studio"])diff --git a/vibe/cli.py b/vibe/cli.pyindex 6fa13bc69..8d246b412 100644--- a/vibe/cli.py+++ b/vibe/cli.py@@ -1809,14 +1809,10 @@ def _doctor():return result-def cmd_vibe():+def cmd_start():paths.ensure_data_dirs()config = _ensure_config()- if runtime.runtime_processes_stale_after_package_update():- logger.info("Running Vibe processes predate the installed package; running explicit restart")- return _cmd_restart_with_delay(0.0)-has_configured_platform_credentials = getattr(config, "has_configured_platform_credentials", None)if callable(has_configured_platform_credentials):ready = bool(has_configured_platform_credentials())@@ -1854,6 +1850,11 @@ def cmd_vibe():return 0+def cmd_vibe():+ """Compatibility default: bare `vibe` restarts during the migration window."""+ return _cmd_restart_with_delay(0.0)++def _stop_opencode_server():"""Terminate the OpenCode server if running."""pid_file = paths.get_logs_dir() / "opencode_server.json"@@ -2345,7 +2346,7 @@ def _cmd_restart_with_delay(delay_seconds: float) -> int:cmd_stop()print("Waiting 3 seconds...")time.sleep(3)- return cmd_vibe()+ return cmd_start()def build_parser():@@ -2353,6 +2354,7 @@ def build_parser():subparsers = parser.add_subparsers(dest="command")subparsers.add_parser("stop", help="Stop all services")+ subparsers.add_parser("start", help="Start services if needed without stopping running processes")restart_parser = subparsers.add_parser("restart", help="Restart all services")restart_parser.add_argument("--delay-seconds",@@ -2805,6 +2807,8 @@ def main():if args.command == "stop":sys.exit(cmd_stop())+ if args.command == "start":+ sys.exit(cmd_start())if args.command == "restart":sys.exit(_cmd_restart_with_delay(args.delay_seconds))if args.command == "status":diff --git a/vibe/runtime.py b/vibe/runtime.pyindex 540e76478..d2dc9acc0 100644--- a/vibe/runtime.py+++ b/vibe/runtime.py@@ -461,158 +461,6 @@ def _pid_mismatches_service(pid: int) -> bool:return not _command_references_path(command, get_service_main_path())-def _pid_matches_service_process(pid: int) -> bool:- command = get_process_command(pid)- return bool(command and _command_references_path(command, get_service_main_path()))---def _linux_process_start_time(pid: int) -> float | None:- proc_stat = Path(f"/proc/{pid}/stat")- system_stat = Path("/proc/stat")- if not proc_stat.exists() or not system_stat.exists():- return None- try:- boot_time = None- for line in system_stat.read_text(encoding="utf-8").splitlines():- if line.startswith("btime "):- boot_time = int(line.split()[1])- break- if boot_time is None:- return None- stat_text = proc_stat.read_text(encoding="utf-8")- after_command = stat_text.rsplit(")", 1)[1].strip().split()- start_ticks = int(after_command[19])- ticks_per_second = os.sysconf(os.sysconf_names["SC_CLK_TCK"])- return boot_time + (start_ticks / ticks_per_second)- except (OSError, IndexError, KeyError, ValueError):- logger.debug("Failed to read Linux process start time for pid=%s", pid, exc_info=True)- return None---def _parse_ps_elapsed_seconds(value: str) -> int | None:- text = value.strip()- if not text:- return None- days = 0- if "-" in text:- day_text, text = text.split("-", 1)- try:- days = int(day_text)- except ValueError:- return None- parts = text.split(":")- if len(parts) == 2:- hours = 0- minutes_text, seconds_text = parts- elif len(parts) == 3:- hours_text, minutes_text, seconds_text = parts- try:- hours = int(hours_text)- except ValueError:- return None- else:- return None- try:- minutes = int(minutes_text)- seconds = int(seconds_text)- except ValueError:- return None- if min(days, hours, minutes, seconds) < 0 or minutes >= 60 or seconds >= 60:- return None- return (((days * 24) + hours) * 60 + minutes) * 60 + seconds---def _ps_process_start_time(pid: int) -> float | None:- try:- result = subprocess.run(- ["ps", "-p", str(pid), "-o", "etime="],- capture_output=True,- text=True,- timeout=2,- check=False,- )- except (OSError, subprocess.SubprocessError):- logger.debug("Failed to invoke ps for process start time pid=%s", pid, exc_info=True)- return None- if result.returncode != 0:- return None- elapsed_seconds = _parse_ps_elapsed_seconds(result.stdout)- if elapsed_seconds is None:- logger.debug("Failed to parse ps elapsed time for pid=%s: %s", pid, result.stdout.strip())- return None- return time.time() - elapsed_seconds---def get_process_start_time(pid: int) -> float | None:- if not isinstance(pid, int) or pid <= 0:- return None- if os.name == "posix":- return _linux_process_start_time(pid) or _ps_process_start_time(pid)- return None---def _current_package_mtime() -> float | None:- # Only use this in installed-package mode. In a source checkout, editing- # files while a dev service is running should not make bare `vibe` restart.- if (get_project_root() / "main.py").exists():- return None-- markers = [- get_package_root() / "__init__.py",- get_service_main_path(),- get_package_root() / "ui_server.py",- ]- mtimes: list[float] = []- for marker in markers:- try:- mtimes.append(marker.stat().st_mtime)- except OSError:- continue- if not mtimes:- return None- return max(mtimes)---def _process_predates_current_package(pid: int) -> bool:- package_mtime = _current_package_mtime()- process_start_time = get_process_start_time(pid)- if package_mtime is None or process_start_time is None:- return False- return process_start_time + 1.0 < package_mtime---def runtime_processes_stale_after_package_update() -> bool:- service_pid_path = paths.get_runtime_pid_path()- if service_pid_path.exists():- try:- service_pid = int(service_pid_path.read_text(encoding="utf-8").strip())- except (OSError, ValueError):- service_pid = 0- if (- service_pid- and pid_alive(service_pid)- and _pid_matches_service_process(service_pid)- and _process_predates_current_package(service_pid)- ):- return True-- ui_pid_path = paths.get_runtime_ui_pid_path()- if ui_pid_path.exists():- try:- ui_pid = int(ui_pid_path.read_text(encoding="utf-8").strip())- except (OSError, ValueError):- ui_pid = 0- if (- ui_pid- and pid_alive(ui_pid)- and _pid_matches_ui_server(ui_pid)- and _process_predates_current_package(ui_pid)- ):- return True-- return False--def render_status():status = read_status()pid_path = paths.get_runtime_pid_path()