Skip to content

Commit 57534cf

Browse files
authored
feat(daemon): replace 5min idle timeout with long-lived daemon model (#641)
* docs: add daemon lifecycle redesign spec Replace the aggressive 5-minute idle timeout with a long-lived daemon model that stays running for hours, reducing restart overhead during development cycles. * docs: add daemon lifecycle redesign implementation plan 8-task TDD plan for replacing aggressive 5-minute idle timeout with long-lived daemon model (4h default, dual-condition exit). * feat(daemon): add DEFAULT_DAEMON_IDLE_TIMEOUT constant (4 hours) * feat(daemon): replace fixed 5min timeout with dual-condition idle manager (4h default) * feat(extension): reduce WS reconnect backoff cap from 60s to 5s * feat(daemon): improve CLI connection-waiting UX with progress messages and 200ms polling * feat(daemon): add opencli daemon status/stop/restart commands * test(daemon): add tests for daemon status/stop commands * fix(daemon): address code review issues — stale constant, restart robustness, timer cleanup, test coverage * docs: update daemon documentation for new lifecycle and CLI commands - troubleshooting.md: replace manual curl/pkill with `opencli daemon status/stop/restart` - browser-bridge.md (en/zh): add Daemon Lifecycle section - README.md: add `opencli daemon status` to Quick Start - README.zh-CN.md: add daemon management commands to tips
1 parent 62fde40 commit 57534cf

17 files changed

Lines changed: 1690 additions & 38 deletions

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ npm install -g @jackwener/opencli
7272
### 3. Verify & Try
7373

7474
```bash
75-
opencli doctor # Check extension + daemon connectivity
75+
opencli doctor # Check extension + daemon connectivity
76+
opencli daemon status # Check daemon state (PID, uptime, memory)
7677
```
7778

7879
**Try it out:**

README.zh-CN.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,11 @@ OpenCLI 通过轻量化的 **Browser Bridge** Chrome 扩展 + 微型 daemon 与
7373

7474
完成!运行任何 opencli 浏览器命令时,后台微型 daemon 会自动启动与浏览器通信。无需配 API Token,零代码配置。
7575

76-
> **Tip**后续诊断用 `opencli doctor`
76+
> **Tip**后续诊断和 daemon 管理
7777
> ```bash
7878
> opencli doctor # 检查扩展和 daemon 连通性
79+
> opencli daemon status # 查看 daemon 状态
80+
> opencli daemon stop # 停止 daemon
7981
> ```
8082
8183
## 快速开始

docs/guide/browser-bridge.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,15 @@ opencli doctor # Check extension + daemon connectivity
3535
```
3636

3737
The daemon manages the WebSocket connection between your CLI commands and the Chrome extension. The extension executes JavaScript in the context of web pages, with access to the logged-in session.
38+
39+
## Daemon Lifecycle
40+
41+
The daemon auto-starts on first browser command and stays alive for **4 hours** by default. It exits only when both conditions are met: no CLI requests for the timeout period AND no Chrome extension connected.
42+
43+
```bash
44+
opencli daemon status # Check daemon state (PID, uptime, extension, memory)
45+
opencli daemon stop # Graceful shutdown
46+
opencli daemon restart # Stop + restart
47+
```
48+
49+
Override the timeout via the `OPENCLI_DAEMON_TIMEOUT` environment variable (milliseconds). Set to `0` to keep the daemon alive indefinitely.

docs/guide/troubleshooting.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,22 @@
2020
### Daemon issues
2121

2222
```bash
23-
# Check daemon status
24-
curl localhost:19825/status
23+
# Check daemon status (PID, uptime, extension connection, memory)
24+
opencli daemon status
2525

2626
# View extension logs
2727
curl localhost:19825/logs
2828

29-
# Kill and restart daemon
30-
pkill -f opencli-daemon
29+
# Stop or restart the daemon
30+
opencli daemon stop
31+
opencli daemon restart
32+
33+
# Full diagnostics
3134
opencli doctor
3235
```
3336

37+
> The daemon auto-exits after 4 hours of inactivity (no CLI requests and no extension connection). Override with `OPENCLI_DAEMON_TIMEOUT` (milliseconds, `0` = never timeout).
38+
3439
### Desktop adapter connection issues
3540

3641
For Electron/CDP-based adapters (Cursor, Codex, etc.):

0 commit comments

Comments
 (0)