Repository navigation
cli: bundle the CodeRouter CLI so cmux coderouter works on a fresh Mac #12104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
389c21f
111c0fb
be72af6
600356e
3b6f7e8
f27b504
e5d60fb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -89,7 +89,7 @@ Environment: | |
| | `automation` | Manage config-backed event rules: `list`, `show <id>`, dry-run `test <id> --event <json>`, `enable`, `disable`, `logs`, and `reload`. Rules live in `~/.cmuxterm/automations.json`; actions are dispatched by the running app. | | ||
| | `sessions [list]` | List saved agent session records without requiring a running cmux socket. Filters: `--agent <name>`, `--session <id>`, `--workspace <id>`, `--surface <id>`, `--cwd <text>`. Overrides: `--state-dir <path>`, `--codex-home <path>`. Text output defaults to 100 results; `--limit <n>` takes a positive integer and `--all` removes the limit. Supports `--json`. | | ||
| | `auth` | Manage auth status, login, and logout through the app. | | ||
| | `coderouter`, `cr` | `cmux coderouter <status|machines|claude>` manages the team's coderouter model plane through the app (sign-in state, per-machine usage, the team's Claude upstream accounts). Every other `cmux coderouter ...` verb and all of `cmux cr ...` exec the installed CodeRouter CLI (`coderouter` or `cr` on PATH) unchanged, exit 127 when it is missing. | | ||
| | `coderouter`, `cr` | `cmux coderouter <status|machines|claude>` manages the team's coderouter model plane through the app (sign-in state, per-machine usage, the team's Claude upstream accounts). Every other `cmux coderouter ...` verb and all of `cmux cr ...` exec the CodeRouter CLI unchanged: a user install (`coderouter` or `cr` on PATH) first, else the copy bundled in `Contents/Resources/bin/coderouter` (pinned by `scripts/coderouter-cli-version`, installed by `scripts/install-coderouter-cli.sh`), so a fresh Mac needs no separate install. Exit 127 only when neither exists. | | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win Rewrite the pipe-separated syntax in the table cell. The pipe characters split this row into extra Markdown table columns. Markdownlint reports MD056, and the rendered contract can lose part of the command description. Use comma-separated alternatives or move the syntax outside the table. 🧰 Tools🪛 markdownlint-cli2 (0.23.2)[warning] 92-92: Spaces inside code span elements (MD038, no-space-in-code) [warning] 92-92: Spaces inside code span elements (MD038, no-space-in-code) [warning] 92-92: Table column count (MD056, table-column-count) 🤖 Prompt for AI AgentsSource: Linters/SAST tools |
||
| | `vm`, `cloud` | Manage cloud VMs. `cloud` is an alias for `vm`. | | ||
| | `remotes`, `remote` | Manage remote Macs in the team device registry so they appear in the iOS app's device list. `remote` is an alias for `remotes`. | | ||
| | `rpc` | Call a raw v2 socket method with optional JSON params. | | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| 0.3.5 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| #!/usr/bin/env bash | ||
| # Installs the CodeRouter CLI into an app bundle as Contents/Resources/bin/coderouter, | ||
| # the same way the cmux-tui client is bundled: a fresh Mac gets `cmux coderouter ...` | ||
| # and `cmux cr ...` with no separate install, no Node, and no PATH setup. | ||
| # | ||
| # The build comes from the public manaflow-ai/coderouter-releases GitHub release named | ||
| # in scripts/coderouter-cli-version (or CMUX_CODEROUTER_CLI_VERSION). Both darwin | ||
| # slices are downloaded, sha256-verified against that release's manifest.json, and | ||
| # lipo'd into one universal binary. Downloads are cached per version. | ||
| # | ||
| # scripts/install-coderouter-cli.sh <app-path> [--version <x.y.z>] [--cache-dir <dir>] | ||
| # | ||
| # Env: CMUX_CODEROUTER_CLI_VERSION overrides the pinned version, CMUX_CODEROUTER_CLI_LOCAL | ||
| # points at a prebuilt binary to install instead of downloading (offline/dev builds), | ||
| # CMUX_CODEROUTER_CLI_BASE_URL overrides the release download base (tests, mirrors). | ||
| set -euo pipefail | ||
|
|
||
| usage() { sed -n '2,15p' "$0"; } | ||
|
|
||
| SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" | ||
| APP_PATH="" | ||
| VERSION="${CMUX_CODEROUTER_CLI_VERSION:-}" | ||
| CACHE_DIR="${CMUX_CODEROUTER_CLI_CACHE:-$HOME/Library/Caches/cmux/coderouter-cli}" | ||
| while (( $# )); do | ||
| case "$1" in | ||
| --version) shift; VERSION="${1:?--version needs a value}" ;; | ||
| --cache-dir) shift; CACHE_DIR="${1:?--cache-dir needs a value}" ;; | ||
| -h|--help) usage; exit 0 ;; | ||
| -*) echo "unknown option: $1" >&2; usage >&2; exit 64 ;; | ||
| *) APP_PATH="$1" ;; | ||
| esac | ||
| shift | ||
| done | ||
| [[ -n "$APP_PATH" && -d "$APP_PATH/Contents" ]] || { echo "error: app bundle not found at '${APP_PATH:-<missing>}'" >&2; exit 1; } | ||
| if [[ -z "$VERSION" ]]; then | ||
| VERSION="$(tr -d '[:space:]' < "$SCRIPT_DIR/coderouter-cli-version")" | ||
| fi | ||
| [[ "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+([-.][0-9A-Za-z.]+)?$ ]] || { echo "error: invalid coderouter version '$VERSION'" >&2; exit 1; } | ||
| DEST_DIR="$APP_PATH/Contents/Resources/bin" | ||
| DEST="$DEST_DIR/coderouter" | ||
| mkdir -p "$DEST_DIR" | ||
|
|
||
| sha256_of() { shasum -a 256 "$1" | awk '{print $1}'; } | ||
|
|
||
| # `coderouter capabilities --json` needs no login and no network; it is the | ||
| # credential-free probe the CLI documents for scripts. | ||
| verify_probe() { | ||
| local probe | ||
| probe="$("$DEST" capabilities --json 2>/dev/null || true)" | ||
| [[ "$probe" == *'"product":"coderouter"'* ]] || { | ||
|
coderabbitai[bot] marked this conversation as resolved.
Resolved
|
||
| echo "error: installed binary does not probe as coderouter: $probe" >&2 | ||
| exit 1 | ||
| } | ||
| } | ||
|
|
||
| if [[ -n "${CMUX_CODEROUTER_CLI_LOCAL:-}" ]]; then | ||
| [[ -f "$CMUX_CODEROUTER_CLI_LOCAL" ]] || { echo "error: CMUX_CODEROUTER_CLI_LOCAL not found: $CMUX_CODEROUTER_CLI_LOCAL" >&2; exit 1; } | ||
| install -m 755 "$CMUX_CODEROUTER_CLI_LOCAL" "$DEST" | ||
| verify_probe | ||
| echo "Installed local coderouter CLI at $DEST" | ||
| exit 0 | ||
| fi | ||
|
|
||
| BASE="${CMUX_CODEROUTER_CLI_BASE_URL:-https://github.com/manaflow-ai/coderouter-releases/releases/download}/v$VERSION" | ||
| BUILD_DIR="$CACHE_DIR/$VERSION" | ||
| mkdir -p "$BUILD_DIR" | ||
| MANIFEST="$BUILD_DIR/manifest.json" | ||
|
|
||
| fetch() { # <url> <out> | ||
| curl --proto '=https,file' --tlsv1.2 -fsSL --retry 3 --retry-delay 2 "$1" -o "$2" | ||
|
coderabbitai[bot] marked this conversation as resolved.
Resolved
|
||
| } | ||
|
|
||
| if [[ ! -f "$MANIFEST" ]]; then | ||
| fetch "$BASE/manifest.json" "$MANIFEST.tmp" | ||
| mv -f "$MANIFEST.tmp" "$MANIFEST" | ||
|
coderabbitai[bot] marked this conversation as resolved.
Resolved
|
||
| fi | ||
| MANIFEST_VERSION="$(python3 -c 'import json,sys; print(json.load(open(sys.argv[1]))["version"])' "$MANIFEST")" | ||
| [[ "$MANIFEST_VERSION" == "$VERSION" ]] || { | ||
| echo "error: coderouter manifest version mismatch (expected $VERSION, got $MANIFEST_VERSION)" >&2 | ||
| exit 1 | ||
| } | ||
|
|
||
| fetch_slice() { # <artifact-name> -> path | ||
| local name="$1" want got out | ||
| want="$(python3 -c 'import json,sys; print(json.load(open(sys.argv[1]))["binaries"].get(sys.argv[2], ""))' "$MANIFEST" "$name")" | ||
| [[ "$want" =~ ^[0-9a-f]{64}$ ]] || { echo "error: manifest lacks $name" >&2; exit 1; } | ||
| out="$BUILD_DIR/$name" | ||
| if [[ -f "$out" ]] && [[ "$(sha256_of "$out")" == "$want" ]]; then | ||
| printf '%s' "$out"; return | ||
| fi | ||
| fetch "$BASE/$name" "$out.tmp" | ||
| got="$(sha256_of "$out.tmp")" | ||
| [[ "$got" == "$want" ]] || { echo "error: sha256 mismatch for $name (want $want, got $got)" >&2; rm -f "$out.tmp"; exit 1; } | ||
| mv -f "$out.tmp" "$out" | ||
| printf '%s' "$out" | ||
| } | ||
|
|
||
| ARM="$(fetch_slice coderouter-darwin-arm64)" | ||
| X64="$(fetch_slice coderouter-darwin-x64)" | ||
| UNIVERSAL="$BUILD_DIR/coderouter-universal" | ||
| if [[ ! -f "$UNIVERSAL" ]]; then | ||
| lipo -create "$ARM" "$X64" -output "$UNIVERSAL.tmp" | ||
| mv -f "$UNIVERSAL.tmp" "$UNIVERSAL" | ||
| fi | ||
| install -m 755 "$UNIVERSAL" "$DEST" | ||
| # One arch per invocation: some lipo builds (Xcode 27 beta 4) consume only one | ||
| # arch after -verify_arch and read the second as an extra input file. | ||
| for arch in arm64 x86_64; do lipo "$DEST" -verify_arch "$arch"; done | ||
| verify_probe | ||
| echo "Installed universal coderouter CLI $VERSION at $DEST" | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| #!/usr/bin/env bash | ||
| set -euo pipefail | ||
|
|
||
| ROOT_DIR="$(cd "$(dirname "$0")/.." && pwd)" | ||
| TEST_DIR="$(mktemp -d "${TMPDIR:-/tmp}/cmux-coderouter-install.XXXXXX")" | ||
| trap 'rm -rf "$TEST_DIR"' EXIT | ||
| APP="$TEST_DIR/Test.app" | ||
| mkdir -p "$APP/Contents" | ||
|
|
||
| # A stand-in binary that answers the credential-free probe the installer checks. | ||
| CLIENT="$TEST_DIR/coderouter" | ||
| cat > "$CLIENT" <<'SH' | ||
| #!/bin/sh | ||
| [ "$1" = capabilities ] && [ "$2" = --json ] || exit 64 | ||
| printf '%s\n' '{"product":"coderouter","cliVersion":"0.0.0","protocolVersion":1,"authModes":["standalone-stack"],"features":[]}' | ||
| SH | ||
| chmod +x "$CLIENT" | ||
| BOGUS="$TEST_DIR/not-coderouter" | ||
| printf '#!/bin/sh\nexit 0\n' > "$BOGUS" | ||
| chmod +x "$BOGUS" | ||
|
|
||
| # Local install path (offline/dev builds), through the runner's system Bash 3.2. | ||
| CMUX_CODEROUTER_CLI_LOCAL="$CLIENT" /bin/bash "$ROOT_DIR/scripts/install-coderouter-cli.sh" "$APP" | ||
| cmp "$CLIENT" "$APP/Contents/Resources/bin/coderouter" | ||
| if CMUX_CODEROUTER_CLI_LOCAL="$BOGUS" /bin/bash "$ROOT_DIR/scripts/install-coderouter-cli.sh" "$APP" > "$TEST_DIR/bogus.log" 2>&1; then | ||
| echo "FAIL: installed a binary that does not probe as coderouter" >&2 | ||
| exit 1 | ||
| fi | ||
| grep -q 'does not probe as coderouter' "$TEST_DIR/bogus.log" | ||
|
|
||
| # Download path against a local file:// release mirror: manifest version check, | ||
| # sha256 verification, and lipo into one universal binary. Needs cc and lipo, so | ||
| # it runs on macOS only; the Linux guard job covers the local path above. | ||
| if [[ "$(uname -s)" == "Darwin" ]]; then | ||
| RELEASE="$TEST_DIR/releases/v9.9.9" | ||
| mkdir -p "$RELEASE" | ||
| ARM_SRC="$(mktemp "$TEST_DIR/arm.XXXXXX.c")" | ||
| printf 'int main(void){return 0;}\n' > "$ARM_SRC" | ||
| cc -arch arm64 -o "$RELEASE/coderouter-darwin-arm64" "$ARM_SRC" | ||
| cc -arch x86_64 -o "$RELEASE/coderouter-darwin-x64" "$ARM_SRC" | ||
| sha() { shasum -a 256 "$1" | awk '{print $1}'; } | ||
| cat > "$RELEASE/manifest.json" <<JSON | ||
| {"version":"9.9.9","binaries":{"coderouter-darwin-arm64":"$(sha "$RELEASE/coderouter-darwin-arm64")","coderouter-darwin-x64":"$(sha "$RELEASE/coderouter-darwin-x64")"}} | ||
| JSON | ||
| # The stand-in slices cannot answer the probe, so this exercises everything up | ||
| # to it and expects the probe itself to fail. | ||
| if CMUX_CODEROUTER_CLI_BASE_URL="file://$TEST_DIR/releases" /bin/bash "$ROOT_DIR/scripts/install-coderouter-cli.sh" "$APP" \ | ||
| --version 9.9.9 --cache-dir "$TEST_DIR/cache" > "$TEST_DIR/download.log" 2>&1; then | ||
| echo "FAIL: probe should have rejected the stand-in universal binary" >&2 | ||
| exit 1 | ||
| fi | ||
| grep -q 'does not probe as coderouter' "$TEST_DIR/download.log" | ||
| lipo "$TEST_DIR/cache/9.9.9/coderouter-universal" -verify_arch arm64 | ||
| lipo "$TEST_DIR/cache/9.9.9/coderouter-universal" -verify_arch x86_64 | ||
|
|
||
| # A tampered slice must fail its checksum before anything is installed. | ||
| printf 'x' >> "$RELEASE/coderouter-darwin-x64" | ||
| rm -rf "$TEST_DIR/cache" | ||
| if CMUX_CODEROUTER_CLI_BASE_URL="file://$TEST_DIR/releases" /bin/bash "$ROOT_DIR/scripts/install-coderouter-cli.sh" "$APP" \ | ||
| --version 9.9.9 --cache-dir "$TEST_DIR/cache" > "$TEST_DIR/tamper.log" 2>&1; then | ||
| echo "FAIL: installed a slice with a bad checksum" >&2 | ||
| exit 1 | ||
| fi | ||
| grep -q 'sha256 mismatch for coderouter-darwin-x64' "$TEST_DIR/tamper.log" | ||
| fi | ||
|
|
||
| # The pinned version file is well formed. | ||
| grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+$' "$ROOT_DIR/scripts/coderouter-cli-version" | ||
| echo "PASS: coderouter CLI installation (local, probe, manifest, checksum, universal)" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PATH search prefers unrelated cr
Medium Severity
The new PATH walk tries
coderouterthencrin each directory, so an unrelatedcrearlier on PATH wins over a realcoderouterlater. The previous lookup searched the whole PATH forcoderouterfirst, thencr, which avoids colliding with othercrtools.Reviewed by Cursor Bugbot for commit 3b6f7e8. Configure here.