@weave-os/router 0.2.34 → 0.2.36

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -58,7 +58,7 @@ Codex installs `$router-status`, `$router-off`, `$router-on`, and
58
58
  to the normal provider; Codex does not support third-party `/disable-routing`
59
59
  slash commands. The shell equivalent is `npx @weave-os/router disable-routing`.
60
60
  Cursor has no config file we own — toggle its base URL override in **Settings →
61
- Models** instead.
61
+ Models** instead, with a custom model named `weave-auto`.
62
62
 
63
63
  Pick which models the router is allowed to route to:
64
64
 
package/cc-statusline.sh CHANGED
@@ -360,7 +360,7 @@ weave_sync_commands 2>/dev/null || true
360
360
  # responses can land out of order, and the loser's mv would replace a newer
361
361
  # setting with an older one AND stamp it fresh, pinning the gate on a stale
362
362
  # value for a full TTL. Refreshes are therefore serialized per cache key on a
363
- # mkdir mutex (atomic everywhere; flock is absent on macOS), held across both
363
+ # directory mutex (flock is absent on macOS), held across both
364
364
  # the fetch and the write. A refresh that finds the mutex held exits rather
365
365
  # than queueing — the in-flight one is at least as fresh as anything it would
366
366
  # fetch, so waiting only to overwrite it is the bug. The one path that is not
@@ -411,10 +411,9 @@ weave_hidden_gate() {
411
411
  (
412
412
  exec </dev/null
413
413
 
414
- # Take the per-cache-key mutex, or bail. mkdir is the portable atomic
415
- # test-and-set. A crashed holder would otherwise block refreshes forever,
416
- # so a lock older than the fetch timeout is treated as abandoned and
417
- # reclaimed. Releasing from a trap covers every exit path below.
414
+ # Take the per-cache-key mutex, or bail. Old locks are reclaimed so a
415
+ # crashed holder cannot block refreshes forever. Releasing from a trap
416
+ # covers every exit path below.
418
417
  lock="$cache.lock"
419
418
  if ! mkdir "$lock" 2>/dev/null; then
420
419
  lock_mtime="$(stat -c %Y "$lock" 2>/dev/null || stat -f %m "$lock" 2>/dev/null)" || lock_mtime=0
@@ -438,7 +437,10 @@ weave_hidden_gate() {
438
437
  rm -rf "$dead" 2>/dev/null
439
438
  mkdir "$lock" 2>/dev/null || exit 0
440
439
  fi
441
- trap 'rmdir "$lock" 2>/dev/null' EXIT
440
+ # Some mkdir implementations return success to both racing creators.
441
+ # Shell noclobber supplies the exclusive claim independently of mkdir.
442
+ (set -C; : > "$lock/owner") 2>/dev/null || exit 0
443
+ trap 'rm -f "$lock/owner"; rmdir "$lock" 2>/dev/null' EXIT
442
444
 
443
445
  self_dir="$(cd "$(dirname "$self")" 2>/dev/null && pwd)"
444
446
  settings_base="$HOME"
package/install.sh CHANGED
@@ -250,7 +250,9 @@ print_uninstall_hint() {
250
250
 
251
251
  # offer_launch asks to start the client named in $1 (command in the remaining
252
252
  # args) so a working interactive install ends in the product. The client runs
253
- # as a child, not via exec, so the EXIT trap still removes the temp files.
253
+ # as a child, not via exec, so the EXIT trap still removes the temp files. It
254
+ # inherits the terminal stdin: Bun-based clients crash with EINVAL on macOS
255
+ # when stdin is /dev/tty, which kqueue can't watch.
254
256
  offer_launch() {
255
257
  local label="$1"; shift
256
258
  [ "${WEAVE_SETUP_DEFER_LAUNCH:-}" != "1" ] && [ "$non_interactive" = "false" ] && [ "$quiet" != "true" ] \
@@ -263,7 +265,7 @@ offer_launch() {
263
265
  *) return 0 ;;
264
266
  esac
265
267
  local launch_status=0
266
- "$@" </dev/tty || launch_status=$?
268
+ "$@" || launch_status=$?
267
269
  exit "$launch_status"
268
270
  }
269
271
 
@@ -3197,7 +3199,7 @@ toggle_claude() {
3197
3199
  # is never touched, so this stays out of `git diff`.
3198
3200
  if [ -f "$local_settings_file" ]; then
3199
3201
  jq '{env: (.env // {}), weave_auto_selected: (.model == "weave-auto" or .model == "weave-auto[1m]")}' "$local_settings_file" >"$parked"
3200
- merged="$(jq '.env = ((.env // {} | del(.ANTHROPIC_CUSTOM_HEADERS)) + {ANTHROPIC_BASE_URL: "https://api.anthropic.com"}) | '"$CLAUDE_WEAVE_AUTO_STRIP_JQ" "$local_settings_file")"
3202
+ merged="$(jq '.env = ((.env // {} | del(.ANTHROPIC_CUSTOM_HEADERS, .CLAUDE_CODE_AUTO_MODE_SERVER)) + {ANTHROPIC_BASE_URL: "https://api.anthropic.com"}) | '"$CLAUDE_WEAVE_AUTO_STRIP_JQ" "$local_settings_file")"
3201
3203
  else
3202
3204
  printf '{"env":{}}\n' >"$parked"
3203
3205
  merged='{"env":{"ANTHROPIC_BASE_URL":"https://api.anthropic.com"}}'
@@ -3219,9 +3221,9 @@ toggle_claude() {
3219
3221
  else
3220
3222
  # Park just the router-owned env keys, then strip them so Claude Code
3221
3223
  # falls back to its own Anthropic login.
3222
- jq '{env: ((.env // {}) | {ANTHROPIC_BASE_URL, ANTHROPIC_CUSTOM_HEADERS, ENABLE_TOOL_SEARCH} | with_entries(select(.value != null))), weave_auto_selected: (.model == "weave-auto" or .model == "weave-auto[1m]")}' "$settings_file" >"$parked"
3224
+ jq '{env: ((.env // {}) | {ANTHROPIC_BASE_URL, ANTHROPIC_CUSTOM_HEADERS, ENABLE_TOOL_SEARCH, CLAUDE_CODE_AUTO_MODE_SERVER} | with_entries(select(.value != null))), weave_auto_selected: (.model == "weave-auto" or .model == "weave-auto[1m]")}' "$settings_file" >"$parked"
3223
3225
  chmod 600 "$parked"
3224
- merged="$(jq '(.env // {}) |= del(.ANTHROPIC_BASE_URL, .ANTHROPIC_CUSTOM_HEADERS, .ENABLE_TOOL_SEARCH)
3226
+ merged="$(jq '(.env // {}) |= del(.ANTHROPIC_BASE_URL, .ANTHROPIC_CUSTOM_HEADERS, .ENABLE_TOOL_SEARCH, .CLAUDE_CODE_AUTO_MODE_SERVER)
3225
3227
  | (if (.env // {} | length) == 0 then del(.env) else . end) | '"$CLAUDE_WEAVE_AUTO_STRIP_JQ" "$settings_file")"
3226
3228
  printf '%s\n' "$merged" >"$settings_file"
3227
3229
  fi
@@ -6471,10 +6473,17 @@ start_desktop_shim_service() {
6471
6473
  </plist>
6472
6474
  PLIST
6473
6475
  launchctl bootout "gui/$uid/$desktop_shim_launchd_label" >/dev/null 2>&1 || true
6474
- if ! launchctl bootstrap "gui/$uid" "$plist"; then
6475
- err "launchctl could not start the Claude Desktop proxy from $plist."
6476
- exit 1
6477
- fi
6476
+ # bootout returns before the old agent has exited, and bootstrapping the
6477
+ # same label meanwhile fails (error 5), so a reinstall retries for a bit.
6478
+ local attempt=1
6479
+ until launchctl bootstrap "gui/$uid" "$plist" 2>/dev/null; do
6480
+ if [ "$attempt" -ge 5 ]; then
6481
+ err "launchctl could not start the Claude Desktop proxy from $plist."
6482
+ exit 1
6483
+ fi
6484
+ attempt=$((attempt + 1))
6485
+ sleep 1
6486
+ done
6478
6487
  ok "Claude Desktop proxy runs at login (launchd $desktop_shim_launchd_label)"
6479
6488
  ;;
6480
6489
  Linux)
@@ -7118,7 +7127,7 @@ weave_sync_commands 2>/dev/null || true
7118
7127
  # responses can land out of order, and the loser's mv would replace a newer
7119
7128
  # setting with an older one AND stamp it fresh, pinning the gate on a stale
7120
7129
  # value for a full TTL. Refreshes are therefore serialized per cache key on a
7121
- # mkdir mutex (atomic everywhere; flock is absent on macOS), held across both
7130
+ # directory mutex (flock is absent on macOS), held across both
7122
7131
  # the fetch and the write. A refresh that finds the mutex held exits rather
7123
7132
  # than queueing — the in-flight one is at least as fresh as anything it would
7124
7133
  # fetch, so waiting only to overwrite it is the bug. The one path that is not
@@ -7169,10 +7178,9 @@ weave_hidden_gate() {
7169
7178
  (
7170
7179
  exec </dev/null
7171
7180
 
7172
- # Take the per-cache-key mutex, or bail. mkdir is the portable atomic
7173
- # test-and-set. A crashed holder would otherwise block refreshes forever,
7174
- # so a lock older than the fetch timeout is treated as abandoned and
7175
- # reclaimed. Releasing from a trap covers every exit path below.
7181
+ # Take the per-cache-key mutex, or bail. Old locks are reclaimed so a
7182
+ # crashed holder cannot block refreshes forever. Releasing from a trap
7183
+ # covers every exit path below.
7176
7184
  lock="$cache.lock"
7177
7185
  if ! mkdir "$lock" 2>/dev/null; then
7178
7186
  lock_mtime="$(stat -c %Y "$lock" 2>/dev/null || stat -f %m "$lock" 2>/dev/null)" || lock_mtime=0
@@ -7196,7 +7204,10 @@ weave_hidden_gate() {
7196
7204
  rm -rf "$dead" 2>/dev/null
7197
7205
  mkdir "$lock" 2>/dev/null || exit 0
7198
7206
  fi
7199
- trap 'rmdir "$lock" 2>/dev/null' EXIT
7207
+ # Some mkdir implementations return success to both racing creators.
7208
+ # Shell noclobber supplies the exclusive claim independently of mkdir.
7209
+ (set -C; : > "$lock/owner") 2>/dev/null || exit 0
7210
+ trap 'rm -f "$lock/owner"; rmdir "$lock" 2>/dev/null' EXIT
7200
7211
 
7201
7212
  self_dir="$(cd "$(dirname "$self")" 2>/dev/null && pwd)"
7202
7213
  settings_base="$HOME"
@@ -7971,6 +7982,11 @@ write_claude_settings() {
7971
7982
  # Setting ANTHROPIC_BASE_URL makes Claude Code treat us as non-first-party.
7972
7983
  # Force tool-search deferral to match first-party Claude Code; "auto" can inline
7973
7984
  # every tool schema when the custom endpoint advertises a 200K context window.
7985
+ # Auto mode's server-side classifier only returns verdicts on Anthropic-served
7986
+ # turns; the first routed non-Anthropic turn makes Claude Code fall back for
7987
+ # the session and hold an action behind a "gateway isn't compatible" notice.
7988
+ # Opt out up front so it uses its own classifier requests from the start.
7989
+ # Project scope keeps the opt-out in settings.local.json so `off` can drop it.
7974
7990
  local prompt_hook_scope=""
7975
7991
  if [ -n "$install_dir" ]; then
7976
7992
  prompt_hook_scope=" --dir $(printf '%q' "$install_dir")"
@@ -7987,7 +8003,7 @@ write_claude_settings() {
7987
8003
  hooks: {UserPromptSubmit: [{hooks: [{type: "command", command: ("[ ! -x \"" + $sl + "\" ] || \"" + $sl + "\" --prompt-hook" + $prompt_hook_scope)}]}]}} else {} end)' >"$tmp_patch"
7988
8004
  else
7989
8005
  jq -n --arg attribution "$attribution" --arg url "$base_url" --arg header "$custom_headers" --arg sl "$statusline_path_for_settings" --arg prompt_hook_scope "$prompt_hook_scope" --arg statusline_install "$statusline_install" '{
7990
- env: { ANTHROPIC_BASE_URL: $url, ANTHROPIC_CUSTOM_HEADERS: $header, ENABLE_TOOL_SEARCH: "true" }
8006
+ env: { ANTHROPIC_BASE_URL: $url, ANTHROPIC_CUSTOM_HEADERS: $header, ENABLE_TOOL_SEARCH: "true", CLAUDE_CODE_AUTO_MODE_SERVER: "0" }
7991
8007
  } + (if $attribution == "true" then {attribution: {
7992
8008
  commit: "Co-Authored-By: Weave Router <router@weaveos.com>",
7993
8009
  pr: "🤖 Generated with [Weave Router](https://router.weaveos.com)"
@@ -8036,7 +8052,7 @@ write_claude_settings() {
8036
8052
 
8037
8053
  if [ "$scope" = "project" ] && [ -z "$install_dir" ]; then
8038
8054
  jq -n --arg header "$custom_headers" --arg router_url "$base_url" '{
8039
- env: { ANTHROPIC_CUSTOM_HEADERS: $header, WEAVE_ROUTER_BASE_URL: $router_url }
8055
+ env: { ANTHROPIC_CUSTOM_HEADERS: $header, WEAVE_ROUTER_BASE_URL: $router_url, CLAUDE_CODE_AUTO_MODE_SERVER: "0" }
8040
8056
  }' >"$tmp_patch"
8041
8057
  if [ -f "$local_settings_file" ]; then
8042
8058
  # Also strip ANTHROPIC_BASE_URL: `off` in project scope points this file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@weave-os/router",
3
- "version": "0.2.34",
3
+ "version": "0.2.36",
4
4
  "description": "One-command installer that points Claude Code, Codex, opencode, or pi at the Weave Router. For pi it also ships the routing extension, loaded via pi.extensions.",
5
5
  "bin": {
6
6
  "weave-router": "bin.js",
@@ -67,7 +67,7 @@
67
67
  "url": "git+https://github.com/weave-os/router.git",
68
68
  "directory": "install/npm"
69
69
  },
70
- "homepage": "https://workweave.ai",
70
+ "homepage": "https://weaveos.com/products/router",
71
71
  "license": "Apache-2.0",
72
72
  "keywords": [
73
73
  "weave",
@@ -75,7 +75,13 @@
75
75
  "claude",
76
76
  "claude-code",
77
77
  "anthropic",
78
+ "codex",
79
+ "opencode",
80
+ "openai",
78
81
  "llm-router",
82
+ "model-router",
83
+ "ai-gateway",
84
+ "llm-proxy",
79
85
  "pi",
80
86
  "pi-package"
81
87
  ],
package/uninstall.sh CHANGED
@@ -1419,7 +1419,7 @@ if [ -f "$settings_file" ]; then
1419
1419
  # statusLine or apiKeyHelper would be silently clobbered.
1420
1420
  cleaned="$(jq --arg statusline_setting_owned "$statusline_setting_owned" "$CLAUDE_WEAVE_AUTO_STRIP_JQ"' |
1421
1421
  if .env then
1422
- .env |= (del(.ANTHROPIC_BASE_URL, .ANTHROPIC_AUTH_TOKEN, .ANTHROPIC_CUSTOM_HEADERS, .ENABLE_TOOL_SEARCH))
1422
+ .env |= (del(.ANTHROPIC_BASE_URL, .ANTHROPIC_AUTH_TOKEN, .ANTHROPIC_CUSTOM_HEADERS, .ENABLE_TOOL_SEARCH, .CLAUDE_CODE_AUTO_MODE_SERVER))
1423
1423
  | (if (.env | length) == 0 then del(.env) else . end)
1424
1424
  else . end
1425
1425
  | (if $statusline_setting_owned == "true" then del(.statusLine) else . end)
@@ -1450,7 +1450,7 @@ if [ -n "$local_settings_file" ] && [ -f "$local_settings_file" ]; then
1450
1450
  # router key; scrub both so uninstall fully reverts the local config.
1451
1451
  cleaned="$(jq "$CLAUDE_WEAVE_AUTO_STRIP_JQ"' |
1452
1452
  if .env then
1453
- .env |= (del(.ANTHROPIC_BASE_URL, .ANTHROPIC_AUTH_TOKEN, .ANTHROPIC_CUSTOM_HEADERS, .ENABLE_TOOL_SEARCH, .WEAVE_ROUTER_BASE_URL))
1453
+ .env |= (del(.ANTHROPIC_BASE_URL, .ANTHROPIC_AUTH_TOKEN, .ANTHROPIC_CUSTOM_HEADERS, .ENABLE_TOOL_SEARCH, .CLAUDE_CODE_AUTO_MODE_SERVER, .WEAVE_ROUTER_BASE_URL))
1454
1454
  | (if (.env | length) == 0 then del(.env) else . end)
1455
1455
  else . end
1456
1456
  | del(.apiKeyHelper)
package/windows.js CHANGED
@@ -238,7 +238,8 @@ function installClaude(paths, baseUrl, key, email, attribution) {
238
238
  const optedOutOfAttribution = Object.hasOwn(settings.env || {}, "ANTHROPIC_BASE_URL") && settings.attribution == null;
239
239
  const localSettings = paths.localConfig ? readJson(paths.localConfig) : null;
240
240
  const state = readJson(paths.state);
241
- state.env ||= Object.fromEntries(["ANTHROPIC_BASE_URL", "ENABLE_TOOL_SEARCH"].map((field) => [field, { exists: Object.hasOwn(settings.env || {}, field), value: settings.env?.[field] }]));
241
+ state.env ||= {};
242
+ for (const field of ["ANTHROPIC_BASE_URL", "ENABLE_TOOL_SEARCH", "CLAUDE_CODE_AUTO_MODE_SERVER"]) state.env[field] ||= { exists: Object.hasOwn(settings.env || {}, field), value: settings.env?.[field] };
242
243
  state.attribution ||= Object.fromEntries(Object.keys(claudeAttribution).map((field) => [field, { exists: Object.hasOwn(settings.attribution || {}, field), value: settings.attribution?.[field] }]));
243
244
  state.originalAppHeaders ||= {
244
245
  config: (settings.env?.ANTHROPIC_CUSTOM_HEADERS || "").split("\n").filter((header) => /^X-App:/i.test(header)),
@@ -266,6 +267,7 @@ function installClaude(paths, baseUrl, key, email, attribution) {
266
267
  settings.env.ANTHROPIC_CUSTOM_HEADERS = [...previousHeaders, ...routerHeaders].filter(Boolean).join("\n");
267
268
  }
268
269
  settings.env.ENABLE_TOOL_SEARCH = "true";
270
+ settings.env.CLAUDE_CODE_AUTO_MODE_SERVER = "0";
269
271
  const modelSettings = localSettings || settings;
270
272
  const modelUnset = !process.env.ANTHROPIC_MODEL && [settings, localSettings, readJson(path.join(process.env.USERPROFILE || process.env.HOME, ".claude", "settings.json"))].every((layer) => !layer || (!Object.hasOwn(layer, "model") && !layer.env?.ANTHROPIC_MODEL));
271
273
  modelSettings.modelPicker = { ...(modelSettings.modelPicker || {}) };
@@ -392,6 +394,7 @@ function uninstall(paths, target) {
392
394
  if (!fs.existsSync(paths.state) && ![settings.env?.ANTHROPIC_CUSTOM_HEADERS, localSettings?.env?.ANTHROPIC_CUSTOM_HEADERS].some((headers) => /^X-Weave-Router-Key:/m.test(headers || ""))) return;
393
395
  restoreField(settings.env, "ANTHROPIC_BASE_URL", state.env?.ANTHROPIC_BASE_URL, state.installedBaseUrl || settings.env?.ANTHROPIC_BASE_URL);
394
396
  restoreField(settings.env, "ENABLE_TOOL_SEARCH", state.env?.ENABLE_TOOL_SEARCH, "true");
397
+ restoreField(settings.env, "CLAUDE_CODE_AUTO_MODE_SERVER", state.env?.CLAUDE_CODE_AUTO_MODE_SERVER, "0");
395
398
  for (const layer of [settings, localSettings]) if (layer) stripClaudeWeaveAuto(layer);
396
399
  const customHeaders = (headerBlock, originalAppHeaders) => {
397
400
  const preservedHeaders = (headerBlock || "").split("\n").filter((header) => !/^X-Weave-(?:Router-Key|User-Email|User-Name|Model-Passthrough):/i.test(header) && !/^X-App:\s*claude-code\s*$/i.test(header));