fix: keep updater CLI in sync#211
Conversation
📝 WalkthroughWalkthroughThe update script now discovers the active ChangesClawRouter runtime update flow
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant update.sh
participant npm_registry
participant ClawRouter
participant CLI_shim
participant viem_accounts
update.sh->>npm_registry: fetch latest ClawRouter version
update.sh->>ClawRouter: discover or install package
ClawRouter-->>update.sh: return active package directory
update.sh->>CLI_shim: synchronize clawrouter executable
update.sh->>viem_accounts: resolve wallet accounts from active package
viem_accounts-->>update.sh: derive wallet address
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@scripts/update.sh`:
- Line 104: Update the generated CLI invocation sites in scripts/update.sh to
pass ACTIVE_PACKAGE_DIR as runtime data rather than interpolating it into
JavaScript source. Use an environment variable or process.argv with shell-safe
quoting for the Node commands and generated shim, preserving support for package
paths containing both single and double quotes.
- Around line 68-75: Update the candidate-selection logic around versionOrder so
location priority is ranked before package version, with version and mtime used
only when candidates share the same location priority; ensure the active
priority-0 OpenClaw extension is selected over unrelated npm/projects
installations. After force_install_from_npm, verify that INSTALLED_VER equals
LATEST_VER and enforce the requested version when it does not.
- Around line 22-25: Update the PATH setup in scripts/update.sh to prepend
"$NPM_PREFIX/bin" whenever NPM_PREFIX is set, without requiring the bin
directory to already exist. Keep exporting PATH so the directory created later
by sync_cli_shim is available to subsequent commands.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: ad05d1de-d06a-4228-80c4-0b7007a63ef1
📒 Files selected for processing (1)
scripts/update.sh
| if [ -n "$NPM_PREFIX" ] && [ -d "$NPM_PREFIX/bin" ]; then | ||
| PATH="$NPM_PREFIX/bin:$PATH" | ||
| export PATH | ||
| fi |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Add npm’s bin directory to PATH even when it does not exist yet.
This guard skips the path entry, but sync_cli_shim later creates that directory. Consequently, the newly created clawrouter shim remains unavailable to subsequent commands in this process.
-if [ -n "$NPM_PREFIX" ] && [ -d "$NPM_PREFIX/bin" ]; then
+if [ -n "$NPM_PREFIX" ]; then📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| if [ -n "$NPM_PREFIX" ] && [ -d "$NPM_PREFIX/bin" ]; then | |
| PATH="$NPM_PREFIX/bin:$PATH" | |
| export PATH | |
| fi | |
| if [ -n "$NPM_PREFIX" ]; then | |
| PATH="$NPM_PREFIX/bin:$PATH" | |
| export PATH | |
| fi |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@scripts/update.sh` around lines 22 - 25, Update the PATH setup in
scripts/update.sh to prepend "$NPM_PREFIX/bin" whenever NPM_PREFIX is set,
without requiring the bin directory to already exist. Keep exporting PATH so the
directory created later by sync_cli_shim is available to subsequent commands.
| const versionOrder = best ? compareVersions(pkg.version, best.pkg.version) : 1; | ||
| if ( | ||
| !best || | ||
| versionOrder > 0 || | ||
| (versionOrder === 0 && | ||
| (candidate.priority < best.priority || | ||
| (candidate.priority === best.priority && stat.mtimeMs > best.mtimeMs))) | ||
| ) { |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Select the active location before comparing versions, then enforce the requested version.
A newer package under npm/projects currently overrides the priority-0 OpenClaw extension. The updater can therefore skip updating the actual active package and point the CLI, wallet, and model assets at an unrelated installation.
Rank by location priority first, use version/mtime only within that location, and verify INSTALLED_VER = LATEST_VER after force_install_from_npm.
Also applies to: 663-681
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@scripts/update.sh` around lines 68 - 75, Update the candidate-selection logic
around versionOrder so location priority is ranked before package version, with
version and mtime used only when candidates share the same location priority;
ensure the active priority-0 OpenClaw extension is selected over unrelated
npm/projects installations. After force_install_from_npm, verify that
INSTALLED_VER equals LATEST_VER and enforce the requested version when it does
not.
| rm -f "$bin_dir/clawrouter" | ||
| cat >"$bin_dir/clawrouter" <<EOF | ||
| #!/bin/sh | ||
| exec node "$package_dir/dist/cli.js" "\$@" |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win
Pass ACTIVE_PACKAGE_DIR as data instead of embedding it into source code.
A valid package path containing ' breaks each JavaScript snippet, while " can break the generated CLI shim. Use an environment variable or process.argv for Node and shell-safe quoting when generating the shim.
Also applies to: 199-199, 666-666, 675-675, 831-831, 1132-1132
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@scripts/update.sh` at line 104, Update the generated CLI invocation sites in
scripts/update.sh to pass ACTIVE_PACKAGE_DIR as runtime data rather than
interpolating it into JavaScript source. Use an environment variable or
process.argv with shell-safe quoting for the Node commands and generated shim,
preserving support for package paths containing both single and double quotes.
Summary
Fixes the ClawRouter updater so
curl -fsSL https://blockrun.ai/ClawRouter-update | bashupdates the user-facingclawrouterCLI to the same package OpenClaw installed.What changed
~/.openclaw/npm/projects/*/node_modules/@blockrun/clawrouter~/.openclaw/extensions/clawrouter~/.openclaw/npm/node_modules/@blockrun/clawrouterclawrouterCLI shim to execute the active OpenClaw-installed package.~/.openclaw/extensions/clawrouter.curl | bashpath handling by readingsrc/top-models.jsonfrom the active package instead of$SCRIPT_DIR.PATHsoopenclawis found in non-login shell updater runs.Why
The updater could report success while
clawrouter --versionstayed on an older global npm install. On testbed, OpenClaw installed0.12.229, but the CLI still resolved to global0.12.220.Verification
bash -n scripts/update.shnpm run format:checknpm run typechecknpm run lintclawrouter --versionreturns0.12.229127.0.0.1:8402top-models.jsonmigration no longer fails withENOENTSummary by CodeRabbit