5 Commits
Author SHA1 Message Date
taodeng 8699b2355d feat: update core manager and startup scripts 2026-02-25 21:27:52 +10:00
taodengandClaude Opus 4.6 e38f91ec4a fix: bind 0.0.0.0 by default so remote devices can access OCM
- server.listen was hardcoded to 127.0.0.1, causing ERR_CONNECTION_REFUSED on remote access
- Default to 0.0.0.0, add --host flag to override (e.g. --host 127.0.0.1 for local-only)
- Show LAN IP in startup log for easy remote access
- Startup log and error messages switched to English
- Bump version to v0.5.2

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-25 10:12:36 +00:00
taodeng 6cca232e9e chore: release v0.5.1 and streamline README 2026-02-25 19:54:45 +10:00
taodeng d479116b9f docs: productize README intro 2026-02-24 21:57:01 +10:00
taodeng 1f8d808dc5 docs: add support/donate section 2026-02-24 21:50:33 +10:00
5 changed files with 669 additions and 554 deletions
+55 -2
View File
@@ -1,7 +1,60 @@
# OpenClaw Manager — 开发日志 # OpenClaw Manager — 开发日志
> 最后更新:2026-02-24 > 最后更新:2026-02-25
> 当前版本:v0.5.0 > 当前版本:v0.5.2
---
## v0.5.2 更新日志(2026-02-25
### 修复
**远程访问无法连接(ERR_CONNECTION_REFUSED**
- `server.listen` 原来绑定 `127.0.0.1`(仅本机),远程通过 `http://<IP>:3333` 访问时被直接拒绝
- 改为默认绑定 `0.0.0.0`(所有网卡),远程设备可通过局域网 IP 访问
- 新增 `--host` 命令行参数:需要限制仅本机访问时可用 `--host 127.0.0.1` 覆盖
- 新增 `getLanIP()` 工具函数,自动检测第一个非内部 IPv4 地址
### 改进
**启动日志改为英文**
- 终端启动信息(目录、地址、提示、错误)全部改为英文
- 绑定 `0.0.0.0` 时自动显示局域网地址,方便远程复制:`🌐 LAN: http://192.168.x.x:3333`
- 端口占用、启动失败等错误提示同步改为英文
---
## v0.5.1 更新日志(2026-02-25
### 修复
**Action 菜单英文模式残留中文**
- 修复 Action 菜单下多处弹窗在 EN 模式仍显示中文的问题(日志、回滚、目录切换、命令输出)
- 统一接入 i18n:标题、按钮、说明文案、加载态、空态、确认框、toast 文案
- 菜单项触发后的交互文案现在与语言切换保持一致
### 工程改进
**1) 嵌入脚本转义/语法防护**
- 新增启动时预检:对前端嵌入脚本执行 `node --check` 语法校验
- 若语法异常(常见为 `MAIN_HTML``\n` 转义写错),启动阶段直接报错并给出修复提示,避免浏览器白屏后才发现问题
**2) 单文件结构化重构(保持零依赖)**
- 将主页面模板从单一超长 `MAIN_HTML` 拆分为三段常量:
- `MAIN_HTML_CSS`
- `MAIN_HTML_BODY`
- `MAIN_HTML_SCRIPT`
- 最终由 `MAIN_HTML` 组合输出,保持“单文件 + 零依赖”不变,同时降低维护复杂度
- 修复拆分过程中的脚本模板转义问题:`MAIN_HTML_SCRIPT` 使用普通模板字符串(非 `String.raw`),确保前端脚本内的反引号模板语法可被正确还原
### 其他
- 程序头部版本与启动日志版本更新为 `v0.5.1`
- `start.sh` / `start.bat` 启动横幅版本号同步更新为 `v0.5.1`
- `README` 补充 Git 安装/更新流程(`git clone` / `git pull --ff-only`),并精简中英文功能介绍
- `README` 首屏改版:增加「1 分钟上手」命令区(安装/更新/运行同屏),并将开场介绍改为精简版
- `README` 去重:移除中部重复的安装/更新/运行段落,统一引用首屏快速上手
- `README` 截图区改为首屏精简展示(3 张)+ 折叠更多截图(`<details>`
--- ---
+79 -67
View File
@@ -1,16 +1,33 @@
# OpenClaw Manager (OCM) # OpenClaw Manager (OCM)
> A zero-dependency, single-file web UI for managing [OpenClaw](https://github.com/anthropics/openclaw) AI agents locally. > A zero-dependency, single-file local dashboard for [OpenClaw](https://github.com/anthropics/openclaw) — manage sub-agents, run commands in a built-in CLI, and stop hand-editing JSON.
[中文说明](#中文说明) [中文说明](#中文说明)
--- ---
## What is this? ## Quick Start (1 min)
OpenClaw Manager is a lightweight local web dashboard that lets you visually manage your OpenClaw AI agents, models, auth, cron jobs, and more — without editing JSON files by hand. ```bash
# Install
git clone https://github.com/dtzp555-max/ocm.git
cd ocm
Everything ships as **a single `.js` file** with zero npm dependencies. Just need Node.js 18+. # Update (existing clone)
git pull --ff-only
# Run (no npm install needed)
bash start.sh # macOS / Linux
start.bat # Windows
```
Open [http://localhost:3333](http://localhost:3333).
## Why OCM
- **Single-file + zero dependency**: one `openclaw-manager.js`, no build step
- **Fast daily operations**: agent/model/auth/cron/backup in one local UI
- **Built-in terminal**: run `openclaw` commands with streaming output and presets
## Screenshots ## Screenshots
@@ -24,6 +41,14 @@ View all agents (main + sub-agents) at a glance. Each card shows model, group bi
![Agents](screenshots/agents.png) ![Agents](screenshots/agents.png)
### Built-in CLI Terminal
Run any openclaw command with real-time streaming output. The terminal panel sits at the bottom of the page and expands on demand.
![CLI Overview](screenshots/cli1.png)
<details>
<summary>More screenshots</summary>
### New Subagent Wizard ### New Subagent Wizard
4-step guided wizard to create a sub-agent: basic info → model → personality & memory → confirm. Fully bilingual. 4-step guided wizard to create a sub-agent: basic info → model → personality & memory → confirm. Fully bilingual.
@@ -44,11 +69,6 @@ View, add, enable/disable, and manually trigger openclaw-related cron tasks. Int
![Cron](screenshots/cron.png) ![Cron](screenshots/cron.png)
### Built-in CLI Terminal
Run any openclaw command with real-time streaming output. The terminal panel sits at the bottom of the page and expands on demand.
![CLI Overview](screenshots/cli1.png)
Preset command menu with built-in commands and your personal favorites — one click to run. Preset command menu with built-in commands and your personal favorites — one click to run.
![CLI Presets](screenshots/cli3.png) ![CLI Presets](screenshots/cli3.png)
@@ -56,42 +76,23 @@ Preset command menu with built-in commands and your personal favorites — one c
Command output streams in real-time. Star frequently used commands for quick access, or use the Manage button to organize favorites. Command output streams in real-time. Star frequently used commands for quick access, or use the Manage button to organize favorites.
![CLI Detail](screenshots/cli2.png) ![CLI Detail](screenshots/cli2.png)
</details>
## Features ## Features
- **Agent Management** — Create sub-agents (with wizard), switch models inline, browse & edit workspace files, delete with auto-backup - **Agents & Workspace** — Create sub-agents, switch models inline, and browse/edit workspace files
- **Model Selection** — Change global primary model, edit fallback chain - **Models & Auth** — Manage primary/fallback models and follow provider auth guides
- **Auth Guide** — Step-by-step instructions for configuring each provider (Anthropic, OpenAI, DeepSeek, Google, GitHub Copilot, etc.) - **Ops Panel** — Restart gateway, view logs, run health checks, and switch OpenClaw directory
- **Token Usage Stats** — Parse `gateway.log` for token usage, view cost breakdown by model and day - **Stats & Cron** — Token/cost stats from `gateway.log` plus cron task management
- **Cron Job Management** — View, add, enable/disable, and trigger openclaw-related cron tasks - **Backups** — Local backup/rollback and NAS backup (SFTP/rsync)
- **Workspace File Browser** — Browse all agent workspace files, read-only by default, editable on demand - **Built-in CLI** — Real-time command terminal with presets, favorites, and tab completion
- **Backup & Rollback** — Auto-backup before every write, one-click restore from any snapshot
- **NAS Backup** — SFTP/rsync backup to NAS with legacy SSH cipher compatibility
- **Built-in CLI Terminal** — Run openclaw commands with real-time streaming output, presets, tab completion
- **Health Badge** — Auto-run `openclaw doctor` and show warnings in the header
- **Bilingual UI** — English / 中文, switchable at runtime
- **Cross-platform** — macOS / Linux / Windows
## Requirements ## Requirements
- Node.js >= 18 ([download](https://nodejs.org/)) - Node.js >= 18 ([download](https://nodejs.org/))
- A working [OpenClaw](https://github.com/anthropics/openclaw) installation - A working [OpenClaw](https://github.com/anthropics/openclaw) installation
## Quick Start Install/update/run commands are in **Quick Start (1 min)** above.
```bash
git clone https://github.com/dtzp555-max/ocm.git
cd ocm
# No npm install needed
# macOS / Linux
bash start.sh
# Windows
start.bat
```
Then open http://localhost:3333 in your browser.
### First Run ### First Run
@@ -154,6 +155,12 @@ ocm/
- **Frontend**: Vanilla HTML/CSS/JS embedded in a template literal — no build step, no framework - **Frontend**: Vanilla HTML/CSS/JS embedded in a template literal — no build step, no framework
- **Architecture**: Single-file, zero-dependency, runs anywhere Node.js runs - **Architecture**: Single-file, zero-dependency, runs anywhere Node.js runs
## Support / Donate
If OCM saves you time, consider starring the repo or sponsoring development.
- GitHub Sponsors: *(add link when ready)*
## License ## License
MIT MIT
@@ -166,13 +173,40 @@ MIT
OpenClaw Manager 是一个零依赖的本地 Web 管理界面,用于可视化管理 [OpenClaw](https://github.com/anthropics/openclaw) AI 智能体。所有代码合并在一个 `.js` 文件中,只需要 Node.js 18+,不需要 `npm install` OpenClaw Manager 是一个零依赖的本地 Web 管理界面,用于可视化管理 [OpenClaw](https://github.com/anthropics/openclaw) AI 智能体。所有代码合并在一个 `.js` 文件中,只需要 Node.js 18+,不需要 `npm install`
### 1 分钟上手
```bash
# 首次安装
git clone https://github.com/dtzp555-max/ocm.git
cd ocm
# 已安装后更新
git pull --ff-only
# 运行(无需 npm install
bash start.sh # macOS / Linux
start.bat # Windows
```
访问 [http://localhost:3333](http://localhost:3333)。
### 界面预览 ### 界面预览
#### 模式选择 #### 模式选择
![Landing](screenshots/landing.png) ![Landing](screenshots/landing.png)
#### Agent 管理 & 新建向导 #### Agent 管理
![Agents](screenshots/agents.png) ![Agents](screenshots/agents.png)
#### 内置 CLI 终端
底部终端面板,支持实时流式输出、预设命令、收藏夹、Tab 补全。
![CLI](screenshots/cli1.png)
<details>
<summary>更多截图</summary>
#### 新建向导
![New Subagent](screenshots/subagents.png) ![New Subagent](screenshots/subagents.png)
#### 模型选择 & 操作菜单 #### 模型选择 & 操作菜单
@@ -184,42 +218,20 @@ OpenClaw Manager 是一个零依赖的本地 Web 管理界面,用于可视化
#### Cron 定时任务 #### Cron 定时任务
![Cron](screenshots/cron.png) ![Cron](screenshots/cron.png)
#### 内置 CLI 终端
底部终端面板,支持实时流式输出、预设命令、收藏夹、Tab 补全。
![CLI](screenshots/cli1.png)
![CLI Presets](screenshots/cli3.png) ![CLI Presets](screenshots/cli3.png)
![CLI Detail](screenshots/cli2.png) ![CLI Detail](screenshots/cli2.png)
</details>
### 功能一览 ### 功能一览
- **Agent 管理** — 新建子智能体(含向导)、内联切换模型、查看/编辑工作区文件、删除(自动备份) - **Agent 与 Workspace** — 新建子智能体、内联切换模型、浏览/编辑工作区文件
- **模型选择** — 修改全局主模型、编辑 Fallback 链 - **模型与认证** — 管理主模型/Fallback 链,按引导完成各 Provider 认证
- **认证引导** — 各 Provider 分步操作指引 + 一键复制 CLI 命令 - **运维操作面板** — 重启网关、查看日志、健康检查、切换 OpenClaw 目录
- **Token 用量统计** — 解析网关日志,按模型/天汇总 Token 和费用 - **统计与计划任务** — 从 `gateway.log` 汇总 Token/费用,并管理 Cron 任务
- **Cron 任务管理** — 查看、添加、启用/禁用、手动触发 openclaw 相关定时任务 - **备份能力** — 本地备份回滚 + NAS 远程备份(SFTP/rsync
- **Workspace 文件浏览器** — 查看所有工作区文件,默认只读,可切换编辑 - **内置 CLI 终端** — 实时输出、预设命令、收藏、Tab 补全
- **备份 & 回滚** — 每次写入前自动备份,一键回滚
- **NAS 备份** — SFTP/rsync 远程备份,兼容老设备 SSH 加密
- **内置 CLI 终端** — 实时流式输出、预设命令、Tab 补全
- **健康检查** — 自动运行 `openclaw doctor`Header 显示状态徽章
- **中英双语** — 运行时随时切换
- **跨平台** — macOS / Linux / Windows
### 快速开始 安装/更新/运行命令见上方 **1 分钟上手**
```bash
git clone https://github.com/dtzp555-max/ocm.git
cd ocm
# macOS / Linux
bash start.sh
# Windows
start.bat
```
访问 http://localhost:3333
### 首次运行 ### 首次运行
+427 -378
View File
File diff suppressed because it is too large Load Diff
+50 -50
View File
@@ -1,13 +1,13 @@
@echo off @echo off
:: ================================================================ :: ================================================================
:: OpenClaw Manager v0.5 — Windows 启动脚本 :: OpenClaw Manager v0.6.0 — Start Script (Windows)
:: ::
:: 特性: :: Features:
:: * 自动检测 Node.js,未安装时给出安装指引(winget/scoop/官网) :: * Auto-detect Node.js, show install instructions if missing
:: * 自动检测 %USERPROFILE%\.openclaw 目录 :: * Auto-detect %USERPROFILE%\.openclaw directory
:: * 首次运行自动创建 manager-config.json :: * Auto-create manager-config.json on first run
:: * 自动检测端口占用并建议替代端口 :: * Auto-kill previous OCM process if port is in use
:: * 支持 --dir / --port / --help 参数 :: * Supports --dir / --port / --host / --help
:: ================================================================ :: ================================================================
setlocal enabledelayedexpansion setlocal enabledelayedexpansion
chcp 65001 >nul 2>&1 chcp 65001 >nul 2>&1
@@ -19,48 +19,47 @@ set "MIN_NODE_MAJOR=18"
echo. echo.
echo =================================== echo ===================================
echo OpenClaw Manager v0.5 echo OpenClaw Manager v0.6.0
echo ----------------------------------- echo -----------------------------------
echo. echo.
:: ── 检查主文件 ──────────────────────────────────────────────── :: ── Check main file ─────────────────────────────────────────
if not exist "%MANAGER_JS%" ( if not exist "%MANAGER_JS%" (
echo [X] 找不到 openclaw-manager.js echo [X] Cannot find openclaw-manager.js
echo 期望路径: %MANAGER_JS% echo Expected: %MANAGER_JS%
echo. echo.
pause pause
exit /b 1 exit /b 1
) )
:: ── 检查 Node.js ───────────────────────────────────────────── :: ── Check Node.js ───────────────────────────────────────────
where node >nul 2>&1 where node >nul 2>&1
if errorlevel 1 ( if errorlevel 1 (
echo [X] 未找到 Node.js echo [X] Node.js not found
echo. echo.
echo 安装方式(选一种即可): echo Install Node.js (pick one):
echo. echo.
echo 1^) winget: winget install OpenJS.NodeJS.LTS echo 1^) winget: winget install OpenJS.NodeJS.LTS
echo 2^) scoop: scoop install nodejs-lts echo 2^) scoop: scoop install nodejs-lts
echo 3^) 官网下载: https://nodejs.org/ echo 3^) Official: https://nodejs.org/
echo 4^) nvm-windows: https://github.com/coreybutler/nvm-windows echo 4^) nvm-windows: https://github.com/coreybutler/nvm-windows
echo. echo.
pause pause
exit /b 1 exit /b 1
) )
:: 获取主版本号并检查
for /f "tokens=1 delims=." %%v in ('node -e "process.stdout.write(process.versions.node)"') do ( for /f "tokens=1 delims=." %%v in ('node -e "process.stdout.write(process.versions.node)"') do (
set "NODE_MAJOR=%%v" set "NODE_MAJOR=%%v"
) )
if !NODE_MAJOR! LSS %MIN_NODE_MAJOR% ( if !NODE_MAJOR! LSS %MIN_NODE_MAJOR% (
echo [!] Node.js 版本过低(需要 ^>= v%MIN_NODE_MAJOR% echo [!] Node.js too old (need ^>= v%MIN_NODE_MAJOR%)
echo. echo.
echo 安装方式(选一种即可): echo Install Node.js (pick one):
echo. echo.
echo 1^) winget: winget install OpenJS.NodeJS.LTS echo 1^) winget: winget install OpenJS.NodeJS.LTS
echo 2^) scoop: scoop install nodejs-lts echo 2^) scoop: scoop install nodejs-lts
echo 3^) 官网下载: https://nodejs.org/ echo 3^) Official: https://nodejs.org/
echo. echo.
pause pause
exit /b 1 exit /b 1
@@ -70,9 +69,10 @@ for /f "tokens=*" %%v in ('node -e "process.stdout.write('v'+process.versions.no
echo [OK] Node.js %%v echo [OK] Node.js %%v
) )
:: ── 解析参数 ───────────────────────────────────────────────── :: ── Parse arguments ─────────────────────────────────────────
set "DIR_ARG=" set "DIR_ARG="
set "PORT_ARG=" set "PORT_ARG="
set "HOST_ARG="
set "EXTRA_ARGS=" set "EXTRA_ARGS="
:parse_args :parse_args
@@ -89,23 +89,29 @@ if /i "%~1"=="--port" (
shift & shift shift & shift
goto :parse_args goto :parse_args
) )
if /i "%~1"=="--host" (
set "HOST_ARG=%~2"
shift & shift
goto :parse_args
)
set "EXTRA_ARGS=!EXTRA_ARGS! %~1" set "EXTRA_ARGS=!EXTRA_ARGS! %~1"
shift shift
goto :parse_args goto :parse_args
:show_help :show_help
echo 用法: start.bat [选项] echo Usage: start.bat [options]
echo. echo.
echo 选项: echo Options:
echo --dir ^<路径^> OpenClaw 配置目录(默认 %%USERPROFILE%%\.openclaw echo --dir ^<path^> OpenClaw config directory (default: %%USERPROFILE%%\.openclaw)
echo --port ^<端口^> 监听端口(默认 3333 echo --port ^<port^> Listen port (default: 3333)
echo --help 显示帮助 echo --host ^<addr^> Bind address (default: 0.0.0.0)
echo --help Show this help
echo. echo.
exit /b 0 exit /b 0
:after_args :after_args
:: ── 检测 OpenClaw 配置目录 ─────────────────────────────────── :: ── Detect OpenClaw config directory ────────────────────────
set "OPENCLAW_DIR=" set "OPENCLAW_DIR="
if defined DIR_ARG ( if defined DIR_ARG (
set "OPENCLAW_DIR=!DIR_ARG!" set "OPENCLAW_DIR=!DIR_ARG!"
@@ -117,54 +123,48 @@ if defined DIR_ARG (
if not defined OPENCLAW_DIR set "OPENCLAW_DIR=%USERPROFILE%\.openclaw" if not defined OPENCLAW_DIR set "OPENCLAW_DIR=%USERPROFILE%\.openclaw"
if exist "!OPENCLAW_DIR!" ( if exist "!OPENCLAW_DIR!" (
echo [OK] 配置目录: !OPENCLAW_DIR! echo [OK] Config dir: !OPENCLAW_DIR!
) else ( ) else (
echo [!] 配置目录不存在: !OPENCLAW_DIR! echo [!] Config dir not found: !OPENCLAW_DIR!
echo 首次使用?请先运行 openclaw onboard 初始化。 echo First time? Run: openclaw onboard
) )
:: ── 首次运行:自动创建 manager-config.json ──────────────────── :: ── First run: auto-create manager-config.json ──────────────
if not exist "%CONFIG_JSON%" ( if not exist "%CONFIG_JSON%" (
echo [-^>] 首次运行,创建 manager-config.json echo [-^>] First run, creating manager-config.json
node -e "require('fs').writeFileSync('%CONFIG_JSON%',JSON.stringify({dir:'~/.openclaw'},null,2))" node -e "require('fs').writeFileSync('%CONFIG_JSON%',JSON.stringify({dir:'~/.openclaw'},null,2))"
) )
:: ── 检查端口可用性 ─────────────────────────────────────────── :: ── Port handling: kill old process if occupied ─────────────
set "PORT=3333" set "PORT=3333"
if defined PORT_ARG set "PORT=!PORT_ARG!" if defined PORT_ARG set "PORT=!PORT_ARG!"
netstat -an 2>nul | findstr /r ":%PORT% .*LISTENING" >nul 2>&1 :: Find PID using the port and kill it
if not errorlevel 1 ( for /f "tokens=5" %%p in ('netstat -ano 2^>nul ^| findstr /r ":!PORT! .*LISTENING"') do (
echo [!] 端口 !PORT! 已被占用 echo [!] Port !PORT! in use (PID %%p), stopping old process...
for %%p in (3334 3335 3336 8080 8888) do ( taskkill /PID %%p /F >nul 2>&1
netstat -an 2>nul | findstr /r ":%%p .*LISTENING" >nul 2>&1 timeout /t 1 /nobreak >nul 2>&1
if errorlevel 1 ( echo [OK] Old process stopped
echo 尝试备用端口 %%p...
set "PORT=%%p"
set "PORT_ARG=%%p"
goto :port_ok
) )
)
)
:port_ok
:: ── 构建启动命令 ───────────────────────────────────────────── :: ── Build launch command ────────────────────────────────────
set "CMD_ARGS=" set "CMD_ARGS="
if defined DIR_ARG set "CMD_ARGS=!CMD_ARGS! --dir "!DIR_ARG!"" if defined DIR_ARG set "CMD_ARGS=!CMD_ARGS! --dir "!DIR_ARG!""
if defined PORT_ARG set "CMD_ARGS=!CMD_ARGS! --port !PORT_ARG!" if defined PORT_ARG set "CMD_ARGS=!CMD_ARGS! --port !PORT_ARG!"
if defined HOST_ARG set "CMD_ARGS=!CMD_ARGS! --host !HOST_ARG!"
if defined EXTRA_ARGS set "CMD_ARGS=!CMD_ARGS! !EXTRA_ARGS!" if defined EXTRA_ARGS set "CMD_ARGS=!CMD_ARGS! !EXTRA_ARGS!"
echo. echo.
echo [^>] 启动中 -^> http://localhost:!PORT! echo [^>] Starting -^> http://localhost:!PORT!
echo Ctrl+C 停止 echo Ctrl+C to stop
echo. echo.
:: ── 启动 ───────────────────────────────────────────────────── :: ── Launch ──────────────────────────────────────────────────
node "%MANAGER_JS%"!CMD_ARGS! node "%MANAGER_JS%"!CMD_ARGS!
if errorlevel 1 ( if errorlevel 1 (
echo. echo.
echo [X] 启动失败,请检查上方错误信息。 echo [X] Failed to start. Check errors above.
pause pause
) )
endlocal endlocal
+55 -54
View File
@@ -1,13 +1,13 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# ================================================================ # ================================================================
# OpenClaw Manager v0.5 — 跨平台启动脚本 (macOS / Linux) # OpenClaw Manager v0.6.0 — Start Script (macOS / Linux)
# #
# 特性: # Features:
# • 自动检测 Node.js,未安装时给出安装指引 # - Auto-detect Node.js, show install instructions if missing
# • 自动检测 ~/.openclaw 目录,不存在时提示 # - Auto-detect ~/.openclaw directory
# • 首次运行自动创建 manager-config.json # - Auto-create manager-config.json on first run
# • 自动检测端口占用并建议替代端口 # - Auto-kill previous OCM process if port is in use
# • 支持 --dir / --port / --help 参数 # - Supports --dir / --port / --host / --help
# ================================================================ # ================================================================
set -e set -e
@@ -16,62 +16,63 @@ MANAGER_JS="$SCRIPT_DIR/openclaw-manager.js"
CONFIG_JSON="$SCRIPT_DIR/manager-config.json" CONFIG_JSON="$SCRIPT_DIR/manager-config.json"
MIN_NODE_MAJOR=18 MIN_NODE_MAJOR=18
# ── 颜色 ───────────────────────────────────────────────────── # ── Colors ────────────────────────────────────────────────────
RED='\033[0;31m'; YELLOW='\033[1;33m'; GREEN='\033[0;32m' RED='\033[0;31m'; YELLOW='\033[1;33m'; GREEN='\033[0;32m'
CYAN='\033[0;36m'; BOLD='\033[1m'; DIM='\033[2m'; RESET='\033[0m' CYAN='\033[0;36m'; BOLD='\033[1m'; DIM='\033[2m'; RESET='\033[0m'
banner() { banner() {
echo "" echo ""
echo -e "${CYAN}${BOLD} 🦀 OpenClaw Manager v0.5${RESET}" echo -e "${CYAN}${BOLD} 🦀 OpenClaw Manager v0.6.0${RESET}"
echo -e "${DIM} ─────────────────────────────${RESET}" echo -e "${DIM} ─────────────────────────────${RESET}"
echo "" echo ""
} }
banner banner
# ── 检查主文件 ──────────────────────────────────────────────── # ── Check main file ──────────────────────────────────────────
if [ ! -f "$MANAGER_JS" ]; then if [ ! -f "$MANAGER_JS" ]; then
echo -e "${RED}找不到 openclaw-manager.js${RESET}" echo -e "${RED}Cannot find openclaw-manager.js${RESET}"
echo -e " 期望路径: ${DIM}$MANAGER_JS${RESET}" echo -e " Expected: ${DIM}$MANAGER_JS${RESET}"
exit 1 exit 1
fi fi
# ── 检查 Node.js ──────────────────────────────────────────── # ── Check Node.js ────────────────────────────────────────────
install_node_hint() { install_node_hint() {
echo "" echo ""
echo -e " ${BOLD}安装方式(选一种即可):${RESET}" echo -e " ${BOLD}Install Node.js (pick one):${RESET}"
echo "" echo ""
if [[ "$(uname)" == "Darwin" ]]; then if [[ "$(uname)" == "Darwin" ]]; then
echo -e " ${GREEN}1)${RESET} Homebrew: ${CYAN}brew install node${RESET}" echo -e " ${GREEN}1)${RESET} Homebrew: ${CYAN}brew install node${RESET}"
echo -e " ${GREEN}2)${RESET} 官网下载: ${CYAN}https://nodejs.org/${RESET}" echo -e " ${GREEN}2)${RESET} Official: ${CYAN}https://nodejs.org/${RESET}"
echo -e " ${GREEN}3)${RESET} nvm: ${CYAN}curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash${RESET}" echo -e " ${GREEN}3)${RESET} nvm: ${CYAN}curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash${RESET}"
echo -e " ${DIM}然后 nvm install --lts${RESET}" echo -e " ${DIM}then: nvm install --lts${RESET}"
else else
echo -e " ${GREEN}1)${RESET} apt: ${CYAN}sudo apt install -y nodejs npm${RESET}" echo -e " ${GREEN}1)${RESET} apt: ${CYAN}sudo apt install -y nodejs npm${RESET}"
echo -e " ${GREEN}2)${RESET} 官网下载: ${CYAN}https://nodejs.org/${RESET}" echo -e " ${GREEN}2)${RESET} Official: ${CYAN}https://nodejs.org/${RESET}"
echo -e " ${GREEN}3)${RESET} nvm: ${CYAN}curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash${RESET}" echo -e " ${GREEN}3)${RESET} nvm: ${CYAN}curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash${RESET}"
echo -e " ${DIM}然后 nvm install --lts${RESET}" echo -e " ${DIM}then: nvm install --lts${RESET}"
fi fi
echo "" echo ""
} }
if ! command -v node &>/dev/null; then if ! command -v node &>/dev/null; then
echo -e "${RED} 未找到 Node.js${RESET}" echo -e "${RED}✗ Node.js not found${RESET}"
install_node_hint install_node_hint
exit 1 exit 1
fi fi
NODE_VER=$(node -e "process.stdout.write(String(process.versions.node.split('.')[0]))") NODE_VER=$(node -e "process.stdout.write(String(process.versions.node.split('.')[0]))")
if [ "$NODE_VER" -lt "$MIN_NODE_MAJOR" ]; then if [ "$NODE_VER" -lt "$MIN_NODE_MAJOR" ]; then
echo -e "${YELLOW}⚠ Node.js 版本过低(当前 v$(node -v),需要 >= v${MIN_NODE_MAJOR}${RESET}" echo -e "${YELLOW}⚠ Node.js too old (current $(node -v), need >= v${MIN_NODE_MAJOR})${RESET}"
install_node_hint install_node_hint
exit 1 exit 1
fi fi
echo -e " ${GREEN}${RESET} Node.js $(node -v)" echo -e " ${GREEN}${RESET} Node.js $(node -v)"
# ── 解析参数 ───────────────────────────────────────────────── # ── Parse arguments ──────────────────────────────────────────
DIR_ARG="" DIR_ARG=""
PORT_ARG="" PORT_ARG=""
HOST_ARG=""
EXTRA_ARGS=() EXTRA_ARGS=()
while [[ $# -gt 0 ]]; do while [[ $# -gt 0 ]]; do
@@ -80,20 +81,22 @@ while [[ $# -gt 0 ]]; do
--dir=*) DIR_ARG="${1#*=}"; shift;; --dir=*) DIR_ARG="${1#*=}"; shift;;
--port) PORT_ARG="$2"; shift 2;; --port) PORT_ARG="$2"; shift 2;;
--port=*) PORT_ARG="${1#*=}"; shift;; --port=*) PORT_ARG="${1#*=}"; shift;;
--host) HOST_ARG="$2"; shift 2;;
--host=*) HOST_ARG="${1#*=}"; shift;;
--help|-h) --help|-h)
echo "用法: $0 [选项]" echo "Usage: $0 [options]"
echo "" echo ""
echo "选项:" echo "Options:"
echo " --dir <路径> OpenClaw 配置目录(默认 ~/.openclaw" echo " --dir <path> OpenClaw config directory (default: ~/.openclaw)"
echo " --port <端口> 监听端口(默认 3333" echo " --port <port> Listen port (default: 3333)"
echo " --help 显示帮助" echo " --host <addr> Bind address (default: 0.0.0.0)"
echo " --help Show this help"
exit 0;; exit 0;;
*) EXTRA_ARGS+=("$1"); shift;; *) EXTRA_ARGS+=("$1"); shift;;
esac esac
done done
# ── 检测 OpenClaw 配置目录 ─────────────────────────────────── # ── Detect OpenClaw config directory ─────────────────────────
# 优先级: --dir 参数 > manager-config.json > 环境变量 > 默认
OPENCLAW_DIR="" OPENCLAW_DIR=""
if [ -n "$DIR_ARG" ]; then if [ -n "$DIR_ARG" ]; then
OPENCLAW_DIR="${DIR_ARG/#\~/$HOME}" OPENCLAW_DIR="${DIR_ARG/#\~/$HOME}"
@@ -106,55 +109,53 @@ fi
[ -z "$OPENCLAW_DIR" ] && OPENCLAW_DIR="$HOME/.openclaw" [ -z "$OPENCLAW_DIR" ] && OPENCLAW_DIR="$HOME/.openclaw"
if [ -d "$OPENCLAW_DIR" ]; then if [ -d "$OPENCLAW_DIR" ]; then
echo -e " ${GREEN}${RESET} 配置目录: ${DIM}$OPENCLAW_DIR${RESET}" echo -e " ${GREEN}${RESET} Config dir: ${DIM}$OPENCLAW_DIR${RESET}"
else else
echo -e " ${YELLOW}${RESET} 配置目录不存在: ${DIM}$OPENCLAW_DIR${RESET}" echo -e " ${YELLOW}${RESET} Config dir not found: ${DIM}$OPENCLAW_DIR${RESET}"
echo -e " ${DIM}首次使用?请先运行 openclaw onboard 初始化。${RESET}" echo -e " ${DIM}First time? Run: openclaw onboard${RESET}"
fi fi
# ── 首次运行:自动创建 manager-config.json ──────────────────── # ── First run: auto-create manager-config.json ───────────────
if [ ! -f "$CONFIG_JSON" ]; then if [ ! -f "$CONFIG_JSON" ]; then
echo -e " ${CYAN}${RESET} 首次运行,创建 ${DIM}manager-config.json${RESET}" echo -e " ${CYAN}${RESET} First run, creating ${DIM}manager-config.json${RESET}"
node -e "require('fs').writeFileSync('$CONFIG_JSON',JSON.stringify({dir:'~/.openclaw'},null,2))" node -e "require('fs').writeFileSync('$CONFIG_JSON',JSON.stringify({dir:'~/.openclaw'},null,2))"
fi fi
# ── 检查端口可用性 ─────────────────────────────────────────── # ── Port handling: kill old process if occupied ──────────────
PORT="${PORT_ARG:-3333}" PORT="${PORT_ARG:-3333}"
check_port() { get_port_pid() {
if command -v lsof &>/dev/null; then if command -v lsof &>/dev/null; then
lsof -i :"$1" -sTCP:LISTEN >/dev/null 2>&1 && return 1 lsof -ti :"$1" -sTCP:LISTEN 2>/dev/null || true
elif command -v ss &>/dev/null; then elif command -v ss &>/dev/null; then
ss -tlnp 2>/dev/null | grep -q ":$1 " && return 1 ss -tlnp 2>/dev/null | grep ":$1 " | grep -oP 'pid=\K[0-9]+' || true
elif command -v netstat &>/dev/null; then
netstat -tlnp 2>/dev/null | grep -q ":$1 " && return 1
fi fi
return 0
} }
if ! check_port "$PORT"; then PORT_PID=$(get_port_pid "$PORT")
echo -e " ${YELLOW}${RESET} 端口 ${PORT} 已被占用" if [ -n "$PORT_PID" ]; then
# 尝试找一个可用端口 echo -e " ${YELLOW}${RESET} Port ${PORT} in use (PID ${PORT_PID}), stopping old process..."
for ALT in 3334 3335 3336 8080 8888; do kill "$PORT_PID" 2>/dev/null || true
if check_port "$ALT"; then sleep 1
echo -e " ${DIM}尝试备用端口 ${ALT}...${RESET}" # Force kill if still alive
PORT="$ALT" if kill -0 "$PORT_PID" 2>/dev/null; then
PORT_ARG="$ALT" kill -9 "$PORT_PID" 2>/dev/null || true
break sleep 0.5
fi fi
done echo -e " ${GREEN}${RESET} Old process stopped"
fi fi
# ── 构建启动命令 ───────────────────────────────────────────── # ── Build launch command ─────────────────────────────────────
CMD_ARGS=() CMD_ARGS=()
[ -n "$DIR_ARG" ] && CMD_ARGS+=(--dir "$DIR_ARG") [ -n "$DIR_ARG" ] && CMD_ARGS+=(--dir "$DIR_ARG")
[ -n "$PORT_ARG" ] && CMD_ARGS+=(--port "$PORT_ARG") [ -n "$PORT_ARG" ] && CMD_ARGS+=(--port "$PORT_ARG")
[ -n "$HOST_ARG" ] && CMD_ARGS+=(--host "$HOST_ARG")
CMD_ARGS+=("${EXTRA_ARGS[@]}") CMD_ARGS+=("${EXTRA_ARGS[@]}")
echo "" echo ""
echo -e " ${CYAN}${RESET} 启动中${BOLD}http://localhost:${PORT}${RESET}" echo -e " ${CYAN}${RESET} Starting${BOLD}http://localhost:${PORT}${RESET}"
echo -e " ${DIM}Ctrl+C 停止${RESET}" echo -e " ${DIM}Ctrl+C to stop${RESET}"
echo "" echo ""
# ── 启动 ───────────────────────────────────────────────────── # ── Launch ───────────────────────────────────────────────────
exec node "$MANAGER_JS" "${CMD_ARGS[@]}" exec node "$MANAGER_JS" "${CMD_ARGS[@]}"