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(cli): add delayed restart scheduling
cyhafc67e12367e
diff --git a/docs/CLI.md b/docs/CLI.mdindex 742aa0dea..9b9455b12 100644--- a/docs/CLI.md+++ b/docs/CLI.md@@ -187,15 +187,15 @@ The key difference between commands:| Command | Main Service | OpenCode Server ||---------|--------------|-----------------|-| `vibe` | Restart | **Preserved** |+| `vibe restart` | Restart | **Terminated** || `vibe stop` | Stop | **Terminated** |### Why This Matters-When you run `vibe` to restart:-- Any **running OpenCode tasks continue uninterrupted**-- The new Vibe Remote instance "adopts" the existing OpenCode server-- Session state is preserved+When you run `vibe restart`:+- The main service restarts cleanly+- The UI restarts too+- The OpenCode server is terminated as part of the restartWhen you run `vibe stop`:- **Everything stops cleanly**@@ -206,10 +206,16 @@ When you run `vibe stop`:### Daily Restart-Just want to restart Vibe Remote without interrupting work:+If an agent is triggering the restart from an active conversation, prefer the delayed form for a better user experience:```bash-vibe+vibe restart --delay-seconds 60+```++Just want to restart Vibe Remote immediately:++```bash+vibe restart```### Update OpenCode Configuration@@ -217,7 +223,7 @@ vibeAfter editing `~/.config/opencode/opencode.json`:```bash-vibe stop && vibe+vibe restart --delay-seconds 60```### Update OpenCode Binary@@ -225,7 +231,7 @@ vibe stop && vibeAfter installing a new version of OpenCode:```bash-vibe stop && vibe+vibe restart --delay-seconds 60```### Update Vibe Remote@@ -233,7 +239,7 @@ vibe stop && vibe```bashvibe upgrade# Then restart:-vibe stop && vibe+vibe restart --delay-seconds 60```### Troubleshooting@@ -247,8 +253,8 @@ vibe status# Run diagnosticsvibe doctor-# Full restart (stops everything including OpenCode)-vibe stop && vibe+# Prefer delayed restart when triggered by an agent+vibe restart --delay-seconds 60```## Web UI Controls@@ -257,8 +263,8 @@ The web UI (`http://127.0.0.1:5123`) provides the same controls:| Button | Equivalent CLI | OpenCode Behavior ||--------|---------------|-------------------|-| **Start** | `vibe` | Preserved |-| **Restart** | `vibe` | Preserved |+| **Start** | `vibe` | Starts on demand |+| **Restart** | `vibe restart` | Terminated || **Stop** | `vibe stop` | Terminated |## File Locationsdiff --git a/docs/CLI_ZH.md b/docs/CLI_ZH.mdindex d9c0cfa62..195b5833f 100644--- a/docs/CLI_ZH.md+++ b/docs/CLI_ZH.md@@ -187,15 +187,15 @@ Vibe Remote 管理两类进程:| 命令 | 主服务 | OpenCode 服务器 ||------|--------|-----------------|-| `vibe` | 重启 | **保留** |+| `vibe restart` | 重启 | **终止** || `vibe stop` | 停止 | **终止** |### 为什么这很重要-当你运行 `vibe` 重启时:-- **正在运行的 OpenCode 任务会继续执行**,不会中断-- 新的 Vibe Remote 实例会「认领」现有的 OpenCode 服务器-- 会话状态得以保留+当你运行 `vibe restart` 时:+- 主服务会被干净地重启+- UI 也会一起重启+- OpenCode 服务器会在重启过程中被终止当你运行 `vibe stop` 时:- **一切都会干净地停止**@@ -206,10 +206,16 @@ Vibe Remote 管理两类进程:### 日常重启-只想重启 Vibe Remote,不中断正在进行的工作:+如果是 Agent 在当前会话里触发重启,默认优先用延迟参数,用户体验更好:```bash-vibe+vibe restart --delay-seconds 60+```++如果就是要立刻重启 Vibe Remote:++```bash+vibe restart```### 更新 OpenCode 配置@@ -217,7 +223,7 @@ vibe修改 `~/.config/opencode/opencode.json` 后:```bash-vibe stop && vibe+vibe restart --delay-seconds 60```### 更新 OpenCode 程序@@ -225,7 +231,7 @@ vibe stop && vibe安装新版本 OpenCode 后:```bash-vibe stop && vibe+vibe restart --delay-seconds 60```### 更新 Vibe Remote@@ -233,7 +239,7 @@ vibe stop && vibe```bashvibe upgrade# 然后重启:-vibe stop && vibe+vibe restart --delay-seconds 60```### 故障排查@@ -247,8 +253,8 @@ vibe status# 运行诊断vibe doctor-# 完全重启(停止所有服务包括 OpenCode)-vibe stop && vibe+# 如果是 Agent 触发,优先延迟重启+vibe restart --delay-seconds 60```## Web UI 控制@@ -257,8 +263,8 @@ Web UI (`http://127.0.0.1:5123`) 提供相同的控制功能:| 按钮 | 等效 CLI | OpenCode 行为 ||------|---------|---------------|-| **Start** | `vibe` | 保留 |-| **Restart** | `vibe` | 保留 |+| **Start** | `vibe` | 按需启动 |+| **Restart** | `vibe restart` | 终止 || **Stop** | `vibe stop` | 终止 |## 文件位置diff --git a/docs/COMMANDS.md b/docs/COMMANDS.mdindex fec6bfd09..e2c9a3135 100644--- a/docs/COMMANDS.md+++ b/docs/COMMANDS.md@@ -554,7 +554,25 @@ vibe stopvibe restart```-- equivalent lifecycle intent: stop, wait briefly, start again+- stops the main service+- stops the UI server+- terminates the OpenCode server too+- starts the service again after a brief wait++Optional async scheduling:++```bash+vibe restart --delay-seconds 60+```++- prints a confirmation immediately+- exits without waiting+- runs the restart in the background after the specified delay++Recommended usage:++- prefer `vibe restart --delay-seconds 60` when an agent triggers the restart from an active conversation+- use plain `vibe restart` when the user explicitly wants the restart to happen immediately### `vibe status`@@ -598,7 +616,7 @@ vibe upgrade```- upgrades Vibe Remote using the selected upgrade plan-- recommends `vibe stop && vibe` after success+- usually recommends `vibe restart --delay-seconds 60` after success## 5.2 `vibe task`diff --git a/docs/COMMANDS_ZH.md b/docs/COMMANDS_ZH.mdindex babcd4df3..9df322d08 100644--- a/docs/COMMANDS_ZH.md+++ b/docs/COMMANDS_ZH.md@@ -533,7 +533,25 @@ vibe stopvibe restart```-- 语义上等价于先停再启+- 停止主服务+- 停止 UI 服务+- 同时终止 OpenCode server+- 短暂等待后重新启动服务++可选的异步延迟执行:++```bash+vibe restart --delay-seconds 60+```++- 会立即打印确认信息+- 当前命令立刻返回+- 到达指定延迟后在后台执行重启++推荐用法:++- 如果是 Agent 在活跃会话里触发重启,优先使用 `vibe restart --delay-seconds 60`+- 只有用户明确要求立刻重启时,再使用普通 `vibe restart`### `vibe status`@@ -577,7 +595,7 @@ vibe upgrade```- 按升级计划升级 Vibe Remote-- 成功后通常建议再执行 `vibe stop && vibe`+- 成功后通常建议再执行 `vibe restart --delay-seconds 60`## 5.2 `vibe task`diff --git a/docs/opencode-poll-loop-refactor/TESTING_GUIDE.md b/docs/opencode-poll-loop-refactor/TESTING_GUIDE.mdindex b2a8d4e65..2169c3541 100644--- a/docs/opencode-poll-loop-refactor/TESTING_GUIDE.md+++ b/docs/opencode-poll-loop-refactor/TESTING_GUIDE.md@@ -279,7 +279,7 @@ vibe**Steps:**1. Send prompt with question-2. **Before answering**, restart Vibe: `vibe stop && vibe`+2. **Before answering**, restart Vibe: `vibe restart`3. Check session status4. Try to answer questiondiff --git a/skills/use-vibe-remote/SKILL.md b/skills/use-vibe-remote/SKILL.mdindex 2e0477850..2c5ffb4d9 100644--- a/skills/use-vibe-remote/SKILL.md+++ b/skills/use-vibe-remote/SKILL.md@@ -34,7 +34,7 @@ Follow this skill as an operations playbook for agents, not as end-user marketin6. Only touch the target platform scope in `settings.json`.7. Do not hand-edit `sessions.json` unless the user explicitly asks for low-level recovery work.8. Tell the user whether the change is global or scope-specific.-9. After config changes, recommend `vibe doctor` and usually `vibe stop && vibe`.+9. After config changes, recommend `vibe doctor` and usually `vibe restart --delay-seconds 60`.## Runtime Layout@@ -85,9 +85,11 @@ python3 -c "import json,sys; json.load(open(sys.argv[1]))" "$TARGET_FILE"```bashvibe doctor-vibe stop && vibe+vibe restart --delay-seconds 60```+Use plain `vibe restart` only when the user explicitly wants an immediate restart. For agent-triggered restarts during an active conversation, prefer the delayed form so the agent can send its final reply before the service goes down.+8. Summarize the exact keys changed.## File Responsibilities@@ -577,6 +579,8 @@ Action:Main commands:- `vibe`: start or restart Vibe Remote; preserves the OpenCode server when possible+- `vibe restart --delay-seconds 60`: preferred agent-safe restart; returns immediately and restarts later in the background+- `vibe restart`: immediate full restart; use only when the user explicitly wants it now- `vibe status`: inspect runtime status- `vibe stop`: stop Vibe Remote and the OpenCode server- `vibe doctor`: validate config, CLI availability, and runtime health@@ -586,7 +590,7 @@ Main commands:Useful checks:-- config does not apply: run `vibe doctor`, then `vibe stop && vibe`+- config does not apply: run `vibe doctor`, then prefer `vibe restart --delay-seconds 60`- backend missing: confirm the backend is enabled and the CLI path is executable- channel does not respond: verify the right `settings.json` scope exists and `enabled` is `true`- wrong repository/cwd: inspect `custom_cwd` and `runtime.default_cwd`diff --git a/tests/test_vibe_cli.py b/tests/test_vibe_cli.pyindex e263a5c51..587ca5500 100644--- a/tests/test_vibe_cli.py+++ b/tests/test_vibe_cli.py@@ -92,6 +92,57 @@ def test_cli_stop_opencode_server_uses_runtime_helpers(tmp_path, monkeypatch):assert not pid_file.exists()+def test_cmd_restart_schedules_delayed_restart(monkeypatch, capsys):+ scheduled = {}+ stop_called = []+ start_called = []++ monkeypatch.setattr(cli, "cache_running_vibe_path", lambda: "/usr/local/bin/vibe")+ monkeypatch.setattr(cli, "get_restart_command", lambda vibe_path=None: [vibe_path or "vibe"])+ monkeypatch.setattr(cli, "get_safe_cwd", lambda: "/tmp")+ monkeypatch.setattr(+ cli.api,+ "_spawn_delayed_restart",+ lambda command, cwd, delay_seconds=2.0: scheduled.update(+ {"command": command, "cwd": cwd, "delay_seconds": delay_seconds}+ ),+ )+ monkeypatch.setattr(cli, "cmd_stop", lambda: stop_called.append(True))+ monkeypatch.setattr(cli, "cmd_vibe", lambda: start_called.append(True))++ assert cli._cmd_restart_with_delay(60) == 0+ assert scheduled == {+ "command": ["/usr/local/bin/vibe", "restart"],+ "cwd": "/tmp",+ "delay_seconds": 60,+ }+ assert stop_called == []+ assert start_called == []++ output = capsys.readouterr().out+ assert "Restart scheduled in 1 minute." in output+ assert "delayed restart will run in the background" in output+++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.time, "sleep", lambda seconds: calls.append(("sleep", seconds)))++ assert cli._cmd_restart_with_delay(0) == 0+ assert calls == ["stop", ("sleep", 3), "start"]+++def test_restart_parser_accepts_delay_seconds():+ parser = cli.build_parser()+ args = parser.parse_args(["restart", "--delay-seconds", "60"])++ assert args.command == "restart"+ assert args.delay_seconds == 60++def test_stop_pid_handles_process_lookup_race(monkeypatch):monkeypatch.setattr(runtime.os, "name", "posix", raising=False)monkeypatch.setattr(runtime, "pid_alive", lambda pid: True)diff --git a/vibe/cli.py b/vibe/cli.pyindex 658b79724..47a0bd77c 100644--- a/vibe/cli.py+++ b/vibe/cli.py@@ -36,7 +36,13 @@ from core.watches import (WatchRuntimeStateStore,)from vibe import __version__, api, runtime-from vibe.upgrade import build_upgrade_plan, cache_running_vibe_path, get_latest_version_info, get_safe_cwd+from vibe.upgrade import (+ build_upgrade_plan,+ cache_running_vibe_path,+ get_latest_version_info,+ get_restart_command,+ get_safe_cwd,+)logger = logging.getLogger(__name__)@@ -109,6 +115,13 @@ def _print_task_error(exc: Exception, *, help_command: str | None = None) -> Nonprint(json.dumps(payload, indent=2), file=sys.stderr)+def _non_negative_float(value: str) -> float:+ parsed = float(value)+ if parsed < 0:+ raise argparse.ArgumentTypeError("must be >= 0")+ return parsed++def _task_examples_text() -> str:return dedent("""\@@ -1945,7 +1958,7 @@ def cmd_upgrade():if result.returncode == 0:print("\033[32mUpgrade successful!\033[0m")print("Please restart vibe to use the new version:")- print(" vibe stop && vibe")+ print(" vibe restart")return 0else:print(f"\033[31mUpgrade failed:\033[0m\n{result.stderr}")@@ -1957,6 +1970,36 @@ def cmd_upgrade():def cmd_restart():"""Restart all services (stop + start)."""+ return _cmd_restart_with_delay(0.0)+++def _format_restart_delay(delay_seconds: float) -> str:+ if delay_seconds == int(delay_seconds):+ whole_seconds = int(delay_seconds)+ if whole_seconds % 60 == 0:+ minutes = whole_seconds // 60+ if minutes == 1:+ return "1 minute"+ return f"{minutes} minutes"+ if whole_seconds == 1:+ return "1 second"+ return f"{whole_seconds} seconds"+ return f"{delay_seconds:g} seconds"+++def _schedule_delayed_restart(delay_seconds: float) -> int:+ current_vibe_path = cache_running_vibe_path()+ restart_command = [*get_restart_command(vibe_path=current_vibe_path), "restart"]+ api._spawn_delayed_restart(restart_command, get_safe_cwd(), delay_seconds=delay_seconds)+ print(f"Restart scheduled in {_format_restart_delay(delay_seconds)}.")+ print("This command exits immediately; the delayed restart will run in the background.")+ return 0+++def _cmd_restart_with_delay(delay_seconds: float) -> int:+ if delay_seconds > 0:+ return _schedule_delayed_restart(delay_seconds)+print("Restarting vibe services...")cmd_stop()print("Waiting 3 seconds...")@@ -1969,7 +2012,13 @@ def build_parser():subparsers = parser.add_subparsers(dest="command")subparsers.add_parser("stop", help="Stop all services")- subparsers.add_parser("restart", help="Restart all services")+ restart_parser = subparsers.add_parser("restart", help="Restart all services")+ restart_parser.add_argument(+ "--delay-seconds",+ type=_non_negative_float,+ default=0,+ help="Schedule the restart to run asynchronously after N seconds, then exit immediately.",+ )subparsers.add_parser("status", help="Show service status")subparsers.add_parser("doctor", help="Run diagnostics")subparsers.add_parser("version", help="Show version")@@ -2327,7 +2376,7 @@ def main():if args.command == "stop":sys.exit(cmd_stop())if args.command == "restart":- sys.exit(cmd_restart())+ sys.exit(_cmd_restart_with_delay(args.delay_seconds))if args.command == "status":sys.exit(cmd_status())if args.command == "doctor":