From 29238fc4238ae82c1bef15bbd6324a862060bb51 Mon Sep 17 00:00:00 2001 From: hfshfg <38004547@qq.com> Date: Wed, 17 Jun 2026 12:02:48 +0800 Subject: [PATCH] =?UTF-8?q?fix(portable/mac):=20setup.sh=20=E8=A3=85?= =?UTF-8?q?=E4=B8=8D=E4=B8=8A=20+=20Bonjour=20=E5=B9=BF=E6=92=AD=20+=20?= =?UTF-8?q?=E9=A6=96=E6=AC=A1=E5=90=AF=E5=8A=A8=E6=B5=8F=E8=A7=88=E5=99=A8?= =?UTF-8?q?=E4=B8=8D=E5=BC=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在 macmini (Apple Silicon, macOS 15.6.1) 实测发现并修复 3 个 Mac 版问题: 1. setup.sh 漏 --ignore-scripts → 装不上 openclaw(致命) openclaw 的 preinstall 脚本会调系统 `node`,但便携版用 app/runtime 下的 node(不在 PATH),未装 Node 的 Mac 用户 → "node: command not found" code 127。 两条 npm install 补 --ignore-scripts --no-audit --no-fund --omit=dev,与 Mac-Start.command 的 fallback install 对齐。 2. Mac-Start.command 没关 Bonjour → mDNS 自动对外广播 macOS 上 bonjour 插件 auto-start(Win/Linux 是 opt-in)。实测日志: `bonjour: advertised ... state=announcing` + `no IPv4 address available on utun12`。本地用 Dashboard 不需要 LAN 发现。补 OPENCLAW_DISABLE_BONJOUR=1 (Windows-Start.bat 早已设)。 3. 首次启动浏览器不自动打开(同 issue #46/#48,此前误判 Mac 无此问题) 首次启动实测 94.5s(staging 35 个 bundled deps),但浏览器轮询只等 15s (30×0.5s) 就放弃。改为最多等 ~3 分钟 (180×1s),加"首次启动需 30-90 秒" 提示,超时回退打开 Config Center。 三处修复均已在 macmini 端到端重测通过。 Co-Authored-By: Claude Opus 4.8 (1M context) --- portable/Mac-Start.command | 40 +++++++++++++++++++++++++++++++------- portable/setup.sh | 7 +++++-- 2 files changed, 38 insertions(+), 9 deletions(-) diff --git a/portable/Mac-Start.command b/portable/Mac-Start.command index 80cfc7c..815c22d 100755 --- a/portable/Mac-Start.command +++ b/portable/Mac-Start.command @@ -95,6 +95,11 @@ fi export OPENCLAW_HOME="$DATA_DIR" export OPENCLAW_STATE_DIR="$STATE_DIR" export OPENCLAW_CONFIG_PATH="$CONFIG_FILE" +# U-Claw opens the local dashboard directly; disable mDNS/Bonjour discovery. +# On macOS the bonjour plugin auto-starts and advertises the gateway on the LAN +# (_openclaw-gw._tcp.local), which is unnecessary for local use and triggers +# "no IPv4 address available on utunN" warnings on machines with VPN/Tailscale. +export OPENCLAW_DISABLE_BONJOUR=1 # ---- 7. Check dependencies ---- if [ ! -d "$CORE_DIR/node_modules" ]; then @@ -148,17 +153,38 @@ OPENCLAW_MJS="$CORE_DIR/node_modules/openclaw/openclaw.mjs" "$NODE_BIN" "$OPENCLAW_MJS" gateway run --allow-unconfigured --force --port $PORT & GW_PID=$! -# ---- 11. Wait for gateway, then open browser ---- -for i in $(seq 1 30); do - sleep 0.5 +# ---- 11. 是否已配置模型?openclaw.json 含 "providers" 即视为已配置 (issue #24) ---- +# 已配置:只开 Dashboard,不再每次弹配置页。未配置(首次):开 Config Center 引导填 Key。 +MODEL_CONFIGURED=0 +if grep -q '"providers"' "$CONFIG_FILE" 2>/dev/null; then + MODEL_CONFIGURED=1 +fi + +# ---- 12. Wait for gateway, then open browser ---- +# 首次启动会 staging ~35 个 bundled deps,慢盘上实测可达 90 秒以上,期间端口还没 +# LISTENING。轮询上限必须覆盖这段,否则浏览器在 gateway ready 前就放弃打开,用户 +# 看到"拒绝连接"以为坏了(同 Windows issue #46/#48)。最多等 ~3 分钟(180×1s)。 +echo -e " ${YELLOW}首次启动需准备运行环境,约 30-90 秒,请稍候...${NC}" +GATEWAY_READY=0 +for i in $(seq 1 180); do if curl -s -o /dev/null "http://127.0.0.1:$PORT/" 2>/dev/null; then - # Open Dashboard - open "http://127.0.0.1:$PORT/#token=uclaw" 2>/dev/null || true - # Open Config Center - open "http://127.0.0.1:18788/" 2>/dev/null || true + GATEWAY_READY=1 + if [ "$MODEL_CONFIGURED" = "1" ]; then + # 已配置:只开 Dashboard + open "http://127.0.0.1:$PORT/#token=uclaw" 2>/dev/null || true + else + # 首次:开 Config Center 引导填 Key + open "http://127.0.0.1:18788/" 2>/dev/null || true + fi break fi + sleep 1 done +if [ "$GATEWAY_READY" != "1" ]; then + # 超时回退:gateway 还没就绪也别让用户干等,先开 Config Center + echo -e " ${YELLOW}Gateway 启动较慢,先打开配置中心...${NC}" + open "http://127.0.0.1:18788/" 2>/dev/null || true +fi echo -e " ${GREEN}════════════════════════════════${NC}" echo -e " ${GREEN}🦞 U-Claw is running!${NC}" diff --git a/portable/setup.sh b/portable/setup.sh index 000e34d..3907326 100755 --- a/portable/setup.sh +++ b/portable/setup.sh @@ -131,9 +131,12 @@ PKGJSON fi # Install with China mirror(缓存留盘内,拔盘不留痕) + # --ignore-scripts 必须加:openclaw 的 preinstall 脚本会调系统 `node`,但便携版 + # 用的是 app/runtime 下的 node(不在 PATH),未装 Node 的 Mac 用户会因 + # "node: command not found" 安装失败 (code 127)。与 Mac-Start.command 的 fallback 对齐。 NODE_BIN="$NODE_TARGET/bin/node" NPM_BIN="$NODE_TARGET/bin/npm" - npm_config_cache="$APP_DIR/.npm-cache" "$NODE_BIN" "$NPM_BIN" install --prefix "$CORE_DIR" --registry="$MIRROR" + npm_config_cache="$APP_DIR/.npm-cache" "$NODE_BIN" "$NPM_BIN" install --prefix "$CORE_DIR" --registry="$MIRROR" --ignore-scripts --no-audit --no-fund --omit=dev echo -e " ${GREEN}✓${NC} OpenClaw 安装完成" fi @@ -145,7 +148,7 @@ else echo -e " ${CYAN}↓${NC} 安装 QQ 插件..." NODE_BIN="$NODE_TARGET/bin/node" NPM_BIN="$NODE_TARGET/bin/npm" - npm_config_cache="$APP_DIR/.npm-cache" "$NODE_BIN" "$NPM_BIN" install @sliverp/qqbot@latest --prefix "$CORE_DIR" --registry="$MIRROR" 2>/dev/null || true + npm_config_cache="$APP_DIR/.npm-cache" "$NODE_BIN" "$NPM_BIN" install @sliverp/qqbot@latest --prefix "$CORE_DIR" --registry="$MIRROR" --ignore-scripts --no-audit --no-fund --omit=dev 2>/dev/null || true echo -e " ${GREEN}✓${NC} QQ 插件安装完成" fi