fix: 5 critical bugs from Codex review

1. Windows: change "node npm.cmd" to "call npm.cmd" (npm.cmd is a
   batch wrapper, not a JS file — can't run with node.exe)
2. Build: use pnpm instead of npm (upstream build script calls pnpm
   subcommands that fail without it); add set -eo pipefail
3. Build: fail explicitly when dist/ not generated instead of || true
4. Run scripts: separate first-time onboard from normal startup
   (was running onboard every time, blocking normal launch)
5. Windows .bat: fix findstr patterns for .env dedup with /r flag
This commit is contained in:
dongsheng123132
2026-03-09 11:02:14 +08:00
parent 1b4bfb38d9
commit c556f36d92
5 changed files with 74 additions and 35 deletions

View File

@@ -102,7 +102,7 @@ echo.
echo === 安装 npm 依赖 ===
echo.
cd /d "%OPENCLAW_DIR%"
"%NODE_BIN%" "%NPM_BIN%" install --registry=https://registry.npmmirror.com
call "%NPM_BIN%" install --registry=https://registry.npmmirror.com
echo.
echo 依赖安装完成!
pause
@@ -115,10 +115,10 @@ echo.
if not exist "%OPENCLAW_DIR%\node_modules" (
echo 先安装依赖...
cd /d "%OPENCLAW_DIR%"
"%NODE_BIN%" "%NPM_BIN%" install --registry=https://registry.npmmirror.com
call "%NPM_BIN%" install --registry=https://registry.npmmirror.com
)
cd /d "%OPENCLAW_DIR%"
"%NODE_BIN%" "%NPM_BIN%" run build
call "%NPM_BIN%" run build
echo.
echo 构建完成!
pause
@@ -131,15 +131,22 @@ echo.
if not exist "%OPENCLAW_DIR%\node_modules" (
echo 先安装依赖...
cd /d "%OPENCLAW_DIR%"
"%NODE_BIN%" "%NPM_BIN%" install --registry=https://registry.npmmirror.com
call "%NPM_BIN%" install --registry=https://registry.npmmirror.com
)
if not exist "%OPENCLAW_DIR%\dist" (
echo 先构建...
cd /d "%OPENCLAW_DIR%"
"%NODE_BIN%" "%NPM_BIN%" run build 2>nul
call "%NPM_BIN%" run build 2>nul
)
cd /d "%OPENCLAW_DIR%"
"%NODE_BIN%" openclaw.mjs onboard --install-daemon 2>nul || "%NODE_BIN%" openclaw.mjs 2>nul || "%NODE_BIN%" "%NPM_BIN%" start
REM 首次运行走 onboard之后直接启动
if not exist "%USERPROFILE%\.openclaw\openclaw.json" (
echo 首次配置...
"%NODE_BIN%" openclaw.mjs onboard --install-daemon
)
echo.
echo 启动 OpenClaw 服务...
"%NODE_BIN%" openclaw.mjs 2>nul || call "%NPM_BIN%" start
pause
goto MENU
@@ -166,7 +173,7 @@ if /i "%MODEL%"=="a" (
set /p APIKEY=" 请输入 DeepSeek API Key: "
REM 移除旧配置再写入,避免重复
if exist "%ENV_FILE%" (
findstr /v "^OPENAI_API_KEY= ^OPENAI_BASE_URL=" "%ENV_FILE%" > "%ENV_FILE%.tmp" 2>nul
findstr /v /r "^OPENAI_API_KEY= ^OPENAI_BASE_URL=" "%ENV_FILE%" > "%ENV_FILE%.tmp" 2>nul
move /y "%ENV_FILE%.tmp" "%ENV_FILE%" >nul 2>nul
)
echo OPENAI_API_KEY=!APIKEY!>> "%ENV_FILE%"
@@ -179,7 +186,7 @@ if /i "%MODEL%"=="b" (
echo 获取 API Key: https://platform.moonshot.cn/
set /p APIKEY=" 请输入 Moonshot API Key: "
if exist "%ENV_FILE%" (
findstr /v "^OPENAI_API_KEY= ^OPENAI_BASE_URL=" "%ENV_FILE%" > "%ENV_FILE%.tmp" 2>nul
findstr /v /r "^OPENAI_API_KEY= ^OPENAI_BASE_URL=" "%ENV_FILE%" > "%ENV_FILE%.tmp" 2>nul
move /y "%ENV_FILE%.tmp" "%ENV_FILE%" >nul 2>nul
)
echo OPENAI_API_KEY=!APIKEY!>> "%ENV_FILE%"
@@ -214,7 +221,7 @@ set /p CH=" 请选择 (a-b): "
if not exist "%OPENCLAW_DIR%\node_modules" (
cd /d "%OPENCLAW_DIR%"
"%NODE_BIN%" "%NPM_BIN%" install --registry=https://registry.npmmirror.com
call "%NPM_BIN%" install --registry=https://registry.npmmirror.com
)
cd /d "%OPENCLAW_DIR%"
"%NODE_BIN%" openclaw.mjs onboard
@@ -226,7 +233,7 @@ echo.
echo === 设置国内镜像源 ===
echo.
cd /d "%OPENCLAW_DIR%"
"%NODE_BIN%" "%NPM_BIN%" config set registry https://registry.npmmirror.com --location=project
call "%NPM_BIN%" config set registry https://registry.npmmirror.com --location=project
echo npm 镜像已设置: registry.npmmirror.com
echo 后续 npm install 将自动使用淘宝镜像
pause
@@ -238,7 +245,7 @@ echo === 诊断修复 ===
echo.
if not exist "%OPENCLAW_DIR%\node_modules" (
cd /d "%OPENCLAW_DIR%"
"%NODE_BIN%" "%NPM_BIN%" install --registry=https://registry.npmmirror.com
call "%NPM_BIN%" install --registry=https://registry.npmmirror.com
)
cd /d "%OPENCLAW_DIR%"
"%NODE_BIN%" openclaw.mjs doctor --repair
@@ -323,7 +330,7 @@ set /p RESET_CHOICE=" 选择重置级别: "
if "%RESET_CHOICE%"=="0" goto MENU
if not exist "%OPENCLAW_DIR%\node_modules" (
cd /d "%OPENCLAW_DIR%"
"%NODE_BIN%" "%NPM_BIN%" install --registry=https://registry.npmmirror.com
call "%NPM_BIN%" install --registry=https://registry.npmmirror.com
)
cd /d "%OPENCLAW_DIR%"
@@ -340,7 +347,7 @@ goto MENU
echo.
echo === 清理缓存 ===
echo.
"%NODE_BIN%" "%NPM_BIN%" cache clean --force 2>nul
call "%NPM_BIN%" cache clean --force 2>nul
echo npm 缓存已清理
if exist "%USERPROFILE%\.openclaw\logs" (
rmdir /s /q "%USERPROFILE%\.openclaw\logs" 2>nul

16
uclaw-scripts/启动菜单.command Normal file → Executable file
View File

@@ -122,7 +122,11 @@ ensure_deps() {
if [ ! -d "$OPENCLAW_DIR/dist" ]; then
echo -e " ${YELLOW}正在构建...${NC}"
cd "$OPENCLAW_DIR"
"$NODE_BIN" "$NPM_BIN" run build 2>&1 || true
"$NODE_BIN" "$NPM_BIN" run build 2>&1
if [ ! -d "$OPENCLAW_DIR/dist" ]; then
echo -e " ${RED}构建失败!请检查上方错误信息${NC}"
return 1
fi
echo -e " ${GREEN}构建完成${NC}"
fi
}
@@ -166,9 +170,13 @@ do_run() {
echo ""
ensure_deps
cd "$OPENCLAW_DIR"
"$NODE_BIN" openclaw.mjs onboard --install-daemon 2>&1 || \
"$NODE_BIN" openclaw.mjs 2>&1 || \
"$NODE_BIN" "$NPM_BIN" start 2>&1
# 首次运行走 onboard之后直接启动
if [ ! -f "$HOME/.openclaw/openclaw.json" ]; then
echo -e " ${YELLOW}首次配置...${NC}"
"$NODE_BIN" openclaw.mjs onboard --install-daemon 2>&1
fi
echo -e " ${CYAN}启动 OpenClaw 服务...${NC}"
"$NODE_BIN" openclaw.mjs 2>&1 || "$NODE_BIN" "$NPM_BIN" start 2>&1
}
# [5] 配置国产模型

View File

@@ -34,7 +34,7 @@ if not exist "%OPENCLAW_DIR%\node_modules" (
echo (使用淘宝镜像,请稍等)
echo.
cd /d "%OPENCLAW_DIR%"
"%NODE_BIN%" "%NPM_BIN%" install --registry=https://registry.npmmirror.com
call "%NPM_BIN%" install --registry=https://registry.npmmirror.com
echo.
echo 依赖安装完成!
echo.
@@ -43,14 +43,21 @@ if not exist "%OPENCLAW_DIR%\node_modules" (
if not exist "%OPENCLAW_DIR%\dist" (
echo 首次运行,正在构建...
cd /d "%OPENCLAW_DIR%"
"%NODE_BIN%" "%NPM_BIN%" run build 2>nul
call "%NPM_BIN%" run build 2>nul
echo.
)
echo 正在启动 OpenClaw...
echo.
cd /d "%OPENCLAW_DIR%"
"%NODE_BIN%" openclaw.mjs onboard --install-daemon 2>nul || "%NODE_BIN%" openclaw.mjs 2>nul || "%NODE_BIN%" "%NPM_BIN%" start
REM 首次运行走 onboard之后直接启动
if not exist "%USERPROFILE%\.openclaw\openclaw.json" (
echo 首次配置...
"%NODE_BIN%" openclaw.mjs onboard --install-daemon
)
echo.
echo 启动 OpenClaw 服务...
"%NODE_BIN%" openclaw.mjs 2>nul || call "%NPM_BIN%" start
echo.
echo OpenClaw 已退出

View File

@@ -65,7 +65,12 @@ fi
if [ ! -d "$OPENCLAW_DIR/dist" ]; then
echo -e " ${YELLOW}首次运行,正在构建...${NC}"
cd "$OPENCLAW_DIR"
"$NODE_BIN" "$NPM_BIN" run build 2>&1 || true
"$NODE_BIN" "$NPM_BIN" run build 2>&1
if [ ! -d "$OPENCLAW_DIR/dist" ]; then
echo -e " ${RED}构建失败,请检查错误信息${NC}"
read -p " 按回车键退出..."
exit 1
fi
echo ""
fi
@@ -73,9 +78,16 @@ fi
echo -e " ${CYAN}正在启动 OpenClaw...${NC}"
echo ""
cd "$OPENCLAW_DIR"
"$NODE_BIN" openclaw.mjs onboard --install-daemon 2>&1 || \
"$NODE_BIN" openclaw.mjs 2>&1 || \
"$NODE_BIN" "$NPM_BIN" start 2>&1
# 首次运行走 onboard 配置,之后直接启动
if [ ! -f "$HOME/.openclaw/openclaw.json" ]; then
echo -e " ${YELLOW}首次配置...${NC}"
"$NODE_BIN" openclaw.mjs onboard --install-daemon 2>&1
fi
echo ""
echo -e " ${CYAN}启动 OpenClaw 服务...${NC}"
"$NODE_BIN" openclaw.mjs 2>&1 || "$NODE_BIN" "$NPM_BIN" start 2>&1
echo ""
echo -e " ${YELLOW}OpenClaw 已退出${NC}"