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:
@@ -5,7 +5,7 @@
|
|||||||
# 用法: ./build-uclaw.sh
|
# 用法: ./build-uclaw.sh
|
||||||
# ============================================================
|
# ============================================================
|
||||||
|
|
||||||
set -e
|
set -eo pipefail
|
||||||
|
|
||||||
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||||
UCLAW_DIR="$SCRIPT_DIR/U-Claw"
|
UCLAW_DIR="$SCRIPT_DIR/U-Claw"
|
||||||
@@ -104,21 +104,26 @@ cd "$UCLAW_DIR/openclaw"
|
|||||||
# 设置淘宝镜像
|
# 设置淘宝镜像
|
||||||
"$NODE_BIN" "$NPM_BIN" config set registry https://registry.npmmirror.com --location=project 2>/dev/null || true
|
"$NODE_BIN" "$NPM_BIN" config set registry https://registry.npmmirror.com --location=project 2>/dev/null || true
|
||||||
|
|
||||||
# 安装依赖
|
# 安装 pnpm(OpenClaw build 脚本依赖 pnpm)
|
||||||
info "npm install 中...(可能需要几分钟)"
|
info "安装 pnpm..."
|
||||||
"$NODE_BIN" "$NPM_BIN" install --registry=https://registry.npmmirror.com --prefer-offline 2>&1 | tail -5
|
"$NODE_BIN" "$NPM_BIN" install -g pnpm --registry=https://registry.npmmirror.com 2>&1 | tail -3
|
||||||
|
PNPM_BIN="$NODE_DIR/bin/pnpm"
|
||||||
|
|
||||||
ok "npm 依赖安装完成"
|
# 安装依赖(使用 pnpm,与上游一致)
|
||||||
|
info "pnpm install 中...(可能需要几分钟)"
|
||||||
|
cd "$UCLAW_DIR/openclaw"
|
||||||
|
"$NODE_BIN" "$PNPM_BIN" install --registry=https://registry.npmmirror.com 2>&1 | tail -5
|
||||||
|
ok "依赖安装完成"
|
||||||
|
|
||||||
# ---- 5. 构建 OpenClaw ----
|
# ---- 5. 构建 OpenClaw ----
|
||||||
info "构建 OpenClaw..."
|
info "构建 OpenClaw..."
|
||||||
# 检查是否有 pnpm 可用,OpenClaw 使用 pnpm build
|
|
||||||
if [ -f "$UCLAW_DIR/openclaw/node_modules/.bin/tsdown" ]; then
|
|
||||||
# 尝试简单构建
|
|
||||||
cd "$UCLAW_DIR/openclaw"
|
cd "$UCLAW_DIR/openclaw"
|
||||||
"$NODE_BIN" "$NPM_BIN" run build 2>&1 | tail -10 || warn "build 可能有错误,继续..."
|
"$NODE_BIN" "$PNPM_BIN" run build 2>&1 | tail -10
|
||||||
|
if [ -d "$UCLAW_DIR/openclaw/dist" ]; then
|
||||||
|
ok "构建成功,dist/ 已生成"
|
||||||
|
else
|
||||||
|
error "构建失败:dist/ 目录未生成,请检查错误信息"
|
||||||
fi
|
fi
|
||||||
ok "构建步骤完成"
|
|
||||||
|
|
||||||
cd "$SCRIPT_DIR"
|
cd "$SCRIPT_DIR"
|
||||||
|
|
||||||
|
|||||||
@@ -102,7 +102,7 @@ echo.
|
|||||||
echo === 安装 npm 依赖 ===
|
echo === 安装 npm 依赖 ===
|
||||||
echo.
|
echo.
|
||||||
cd /d "%OPENCLAW_DIR%"
|
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 依赖安装完成!
|
echo 依赖安装完成!
|
||||||
pause
|
pause
|
||||||
@@ -115,10 +115,10 @@ echo.
|
|||||||
if not exist "%OPENCLAW_DIR%\node_modules" (
|
if not exist "%OPENCLAW_DIR%\node_modules" (
|
||||||
echo 先安装依赖...
|
echo 先安装依赖...
|
||||||
cd /d "%OPENCLAW_DIR%"
|
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%"
|
cd /d "%OPENCLAW_DIR%"
|
||||||
"%NODE_BIN%" "%NPM_BIN%" run build
|
call "%NPM_BIN%" run build
|
||||||
echo.
|
echo.
|
||||||
echo 构建完成!
|
echo 构建完成!
|
||||||
pause
|
pause
|
||||||
@@ -131,15 +131,22 @@ echo.
|
|||||||
if not exist "%OPENCLAW_DIR%\node_modules" (
|
if not exist "%OPENCLAW_DIR%\node_modules" (
|
||||||
echo 先安装依赖...
|
echo 先安装依赖...
|
||||||
cd /d "%OPENCLAW_DIR%"
|
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" (
|
if not exist "%OPENCLAW_DIR%\dist" (
|
||||||
echo 先构建...
|
echo 先构建...
|
||||||
cd /d "%OPENCLAW_DIR%"
|
cd /d "%OPENCLAW_DIR%"
|
||||||
"%NODE_BIN%" "%NPM_BIN%" run build 2>nul
|
call "%NPM_BIN%" run build 2>nul
|
||||||
)
|
)
|
||||||
cd /d "%OPENCLAW_DIR%"
|
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
|
pause
|
||||||
goto MENU
|
goto MENU
|
||||||
|
|
||||||
@@ -166,7 +173,7 @@ if /i "%MODEL%"=="a" (
|
|||||||
set /p APIKEY=" 请输入 DeepSeek API Key: "
|
set /p APIKEY=" 请输入 DeepSeek API Key: "
|
||||||
REM 移除旧配置再写入,避免重复
|
REM 移除旧配置再写入,避免重复
|
||||||
if exist "%ENV_FILE%" (
|
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
|
move /y "%ENV_FILE%.tmp" "%ENV_FILE%" >nul 2>nul
|
||||||
)
|
)
|
||||||
echo OPENAI_API_KEY=!APIKEY!>> "%ENV_FILE%"
|
echo OPENAI_API_KEY=!APIKEY!>> "%ENV_FILE%"
|
||||||
@@ -179,7 +186,7 @@ if /i "%MODEL%"=="b" (
|
|||||||
echo 获取 API Key: https://platform.moonshot.cn/
|
echo 获取 API Key: https://platform.moonshot.cn/
|
||||||
set /p APIKEY=" 请输入 Moonshot API Key: "
|
set /p APIKEY=" 请输入 Moonshot API Key: "
|
||||||
if exist "%ENV_FILE%" (
|
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
|
move /y "%ENV_FILE%.tmp" "%ENV_FILE%" >nul 2>nul
|
||||||
)
|
)
|
||||||
echo OPENAI_API_KEY=!APIKEY!>> "%ENV_FILE%"
|
echo OPENAI_API_KEY=!APIKEY!>> "%ENV_FILE%"
|
||||||
@@ -214,7 +221,7 @@ set /p CH=" 请选择 (a-b): "
|
|||||||
|
|
||||||
if not exist "%OPENCLAW_DIR%\node_modules" (
|
if not exist "%OPENCLAW_DIR%\node_modules" (
|
||||||
cd /d "%OPENCLAW_DIR%"
|
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%"
|
cd /d "%OPENCLAW_DIR%"
|
||||||
"%NODE_BIN%" openclaw.mjs onboard
|
"%NODE_BIN%" openclaw.mjs onboard
|
||||||
@@ -226,7 +233,7 @@ echo.
|
|||||||
echo === 设置国内镜像源 ===
|
echo === 设置国内镜像源 ===
|
||||||
echo.
|
echo.
|
||||||
cd /d "%OPENCLAW_DIR%"
|
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 镜像已设置: registry.npmmirror.com
|
||||||
echo 后续 npm install 将自动使用淘宝镜像
|
echo 后续 npm install 将自动使用淘宝镜像
|
||||||
pause
|
pause
|
||||||
@@ -238,7 +245,7 @@ echo === 诊断修复 ===
|
|||||||
echo.
|
echo.
|
||||||
if not exist "%OPENCLAW_DIR%\node_modules" (
|
if not exist "%OPENCLAW_DIR%\node_modules" (
|
||||||
cd /d "%OPENCLAW_DIR%"
|
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%"
|
cd /d "%OPENCLAW_DIR%"
|
||||||
"%NODE_BIN%" openclaw.mjs doctor --repair
|
"%NODE_BIN%" openclaw.mjs doctor --repair
|
||||||
@@ -323,7 +330,7 @@ set /p RESET_CHOICE=" 选择重置级别: "
|
|||||||
if "%RESET_CHOICE%"=="0" goto MENU
|
if "%RESET_CHOICE%"=="0" goto MENU
|
||||||
if not exist "%OPENCLAW_DIR%\node_modules" (
|
if not exist "%OPENCLAW_DIR%\node_modules" (
|
||||||
cd /d "%OPENCLAW_DIR%"
|
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%"
|
cd /d "%OPENCLAW_DIR%"
|
||||||
|
|
||||||
@@ -340,7 +347,7 @@ goto MENU
|
|||||||
echo.
|
echo.
|
||||||
echo === 清理缓存 ===
|
echo === 清理缓存 ===
|
||||||
echo.
|
echo.
|
||||||
"%NODE_BIN%" "%NPM_BIN%" cache clean --force 2>nul
|
call "%NPM_BIN%" cache clean --force 2>nul
|
||||||
echo npm 缓存已清理
|
echo npm 缓存已清理
|
||||||
if exist "%USERPROFILE%\.openclaw\logs" (
|
if exist "%USERPROFILE%\.openclaw\logs" (
|
||||||
rmdir /s /q "%USERPROFILE%\.openclaw\logs" 2>nul
|
rmdir /s /q "%USERPROFILE%\.openclaw\logs" 2>nul
|
||||||
|
|||||||
16
uclaw-scripts/启动菜单.command
Normal file → Executable file
16
uclaw-scripts/启动菜单.command
Normal file → Executable file
@@ -122,7 +122,11 @@ ensure_deps() {
|
|||||||
if [ ! -d "$OPENCLAW_DIR/dist" ]; then
|
if [ ! -d "$OPENCLAW_DIR/dist" ]; then
|
||||||
echo -e " ${YELLOW}正在构建...${NC}"
|
echo -e " ${YELLOW}正在构建...${NC}"
|
||||||
cd "$OPENCLAW_DIR"
|
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}"
|
echo -e " ${GREEN}构建完成${NC}"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
@@ -166,9 +170,13 @@ do_run() {
|
|||||||
echo ""
|
echo ""
|
||||||
ensure_deps
|
ensure_deps
|
||||||
cd "$OPENCLAW_DIR"
|
cd "$OPENCLAW_DIR"
|
||||||
"$NODE_BIN" openclaw.mjs onboard --install-daemon 2>&1 || \
|
# 首次运行走 onboard,之后直接启动
|
||||||
"$NODE_BIN" openclaw.mjs 2>&1 || \
|
if [ ! -f "$HOME/.openclaw/openclaw.json" ]; then
|
||||||
"$NODE_BIN" "$NPM_BIN" start 2>&1
|
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] 配置国产模型
|
# [5] 配置国产模型
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ if not exist "%OPENCLAW_DIR%\node_modules" (
|
|||||||
echo (使用淘宝镜像,请稍等)
|
echo (使用淘宝镜像,请稍等)
|
||||||
echo.
|
echo.
|
||||||
cd /d "%OPENCLAW_DIR%"
|
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 依赖安装完成!
|
echo 依赖安装完成!
|
||||||
echo.
|
echo.
|
||||||
@@ -43,14 +43,21 @@ if not exist "%OPENCLAW_DIR%\node_modules" (
|
|||||||
if not exist "%OPENCLAW_DIR%\dist" (
|
if not exist "%OPENCLAW_DIR%\dist" (
|
||||||
echo 首次运行,正在构建...
|
echo 首次运行,正在构建...
|
||||||
cd /d "%OPENCLAW_DIR%"
|
cd /d "%OPENCLAW_DIR%"
|
||||||
"%NODE_BIN%" "%NPM_BIN%" run build 2>nul
|
call "%NPM_BIN%" run build 2>nul
|
||||||
echo.
|
echo.
|
||||||
)
|
)
|
||||||
|
|
||||||
echo 正在启动 OpenClaw...
|
echo 正在启动 OpenClaw...
|
||||||
echo.
|
echo.
|
||||||
cd /d "%OPENCLAW_DIR%"
|
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.
|
||||||
echo OpenClaw 已退出
|
echo OpenClaw 已退出
|
||||||
|
|||||||
@@ -65,7 +65,12 @@ fi
|
|||||||
if [ ! -d "$OPENCLAW_DIR/dist" ]; then
|
if [ ! -d "$OPENCLAW_DIR/dist" ]; then
|
||||||
echo -e " ${YELLOW}首次运行,正在构建...${NC}"
|
echo -e " ${YELLOW}首次运行,正在构建...${NC}"
|
||||||
cd "$OPENCLAW_DIR"
|
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 ""
|
echo ""
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -73,9 +78,16 @@ fi
|
|||||||
echo -e " ${CYAN}正在启动 OpenClaw...${NC}"
|
echo -e " ${CYAN}正在启动 OpenClaw...${NC}"
|
||||||
echo ""
|
echo ""
|
||||||
cd "$OPENCLAW_DIR"
|
cd "$OPENCLAW_DIR"
|
||||||
"$NODE_BIN" openclaw.mjs onboard --install-daemon 2>&1 || \
|
|
||||||
"$NODE_BIN" openclaw.mjs 2>&1 || \
|
# 首次运行走 onboard 配置,之后直接启动
|
||||||
"$NODE_BIN" "$NPM_BIN" start 2>&1
|
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 ""
|
||||||
echo -e " ${YELLOW}OpenClaw 已退出${NC}"
|
echo -e " ${YELLOW}OpenClaw 已退出${NC}"
|
||||||
|
|||||||
Reference in New Issue
Block a user