@weave-os/router 0.2.32 → 0.2.33
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/cc-statusline.sh +28 -1
- package/install.sh +149 -10
- package/package.json +1 -1
- package/uninstall.sh +9 -2
- package/windows.js +32 -2
package/cc-statusline.sh
CHANGED
|
@@ -377,6 +377,9 @@ weave_hidden_gate() {
|
|
|
377
377
|
local cache="$cache_dir/display-settings${script_slug}"
|
|
378
378
|
local ttl="${WEAVE_DISPLAY_SETTINGS_TTL_SECONDS:-3600}"
|
|
379
379
|
|
|
380
|
+
# Linked plans that need a fresh login, from the last successful refresh.
|
|
381
|
+
weave_disconnected_plans="$(cat "$cache.plans" 2>/dev/null)"
|
|
382
|
+
|
|
380
383
|
local now mtime fresh="false"
|
|
381
384
|
now="$(date +%s 2>/dev/null)" || now=0
|
|
382
385
|
if [ -f "$cache" ]; then
|
|
@@ -476,6 +479,8 @@ weave_hidden_gate() {
|
|
|
476
479
|
else
|
|
477
480
|
printf '0' >"$tmp" 2>/dev/null && mv "$tmp" "$cache" 2>/dev/null
|
|
478
481
|
fi
|
|
482
|
+
plans="$(printf '%s' "$body" | jq -r '[.disconnected_plans[]? | select(type == "string" and test("^[a-z]+$"))] | join(" ")' 2>/dev/null)"
|
|
483
|
+
printf '%s' "$plans" >"$tmp" 2>/dev/null && mv "$tmp" "$cache.plans" 2>/dev/null
|
|
479
484
|
rm -f "$tmp" 2>/dev/null
|
|
480
485
|
) >/dev/null 2>&1 &
|
|
481
486
|
disown 2>/dev/null || true
|
|
@@ -1085,7 +1090,8 @@ brand=$'\033[38;2;255;108;71mWEAVE ROUTER\033[0m'
|
|
|
1085
1090
|
# saving.
|
|
1086
1091
|
short_model() { printf '%s' "${1#claude-}"; }
|
|
1087
1092
|
picked=""
|
|
1088
|
-
|
|
1093
|
+
# Weave Auto is a routing choice, not a model, so only the served model is shown.
|
|
1094
|
+
if [[ -n "$selected_display" && "$selected_display" != "?" && "$requested_norm" != "weave-auto" ]]; then
|
|
1089
1095
|
picked="$(short_model "$requested_norm")"
|
|
1090
1096
|
fi
|
|
1091
1097
|
status_text=""
|
|
@@ -1116,6 +1122,27 @@ if [[ "$has_pin_record" == "true" ]]; then
|
|
|
1116
1122
|
status_text="$status_text · last pin: $last_pin_model"
|
|
1117
1123
|
fi
|
|
1118
1124
|
|
|
1125
|
+
# Point the reconnect command at this install: a bare login reads the
|
|
1126
|
+
# user-scope config, which a project or --dir install doesn't use.
|
|
1127
|
+
weave_login_scope=""
|
|
1128
|
+
if [ -n "${weave_disconnected_plans:-}" ]; then
|
|
1129
|
+
weave_sl_dir="$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" 2>/dev/null && pwd)"
|
|
1130
|
+
case "$weave_sl_dir" in
|
|
1131
|
+
*/.claude)
|
|
1132
|
+
weave_login_scope=" --dir $(printf '%q' "${weave_sl_dir%/.claude}")"
|
|
1133
|
+
if grep -q 'X-Weave-Router-Key' "$weave_sl_dir/settings.local.json" 2>/dev/null; then
|
|
1134
|
+
weave_login_scope=" --scope project$weave_login_scope"
|
|
1135
|
+
fi
|
|
1136
|
+
;;
|
|
1137
|
+
esac
|
|
1138
|
+
fi
|
|
1139
|
+
for weave_plan in ${weave_disconnected_plans:-}; do
|
|
1140
|
+
case "$weave_plan" in
|
|
1141
|
+
claude) status_text="$status_text · Claude plan disconnected: run npx @weave-os/router login claude$weave_login_scope" ;;
|
|
1142
|
+
codex) status_text="$status_text · Codex plan disconnected: run npx @weave-os/router login codex$weave_login_scope" ;;
|
|
1143
|
+
esac
|
|
1144
|
+
done
|
|
1145
|
+
|
|
1119
1146
|
# /router-status reads this back through the prompt hook, so it can answer
|
|
1120
1147
|
# without a model turn.
|
|
1121
1148
|
weave_cache_status_line() {
|
package/install.sh
CHANGED
|
@@ -403,7 +403,7 @@ Set up
|
|
|
403
403
|
$npx setup --claude --codex install for both (one key prompt)
|
|
404
404
|
$npx --opencode | --pi install for opencode or pi
|
|
405
405
|
$npx --copilot add Weave Router to Copilot CLI's /model picker
|
|
406
|
-
$npx --claude-desktop route Claude Desktop's Code tab (local proxy)
|
|
406
|
+
$npx --claude-desktop route Claude Desktop's Code tab and Cowork (local proxy)
|
|
407
407
|
|
|
408
408
|
Every day
|
|
409
409
|
$npx status is each tool routed, signed in, working?
|
|
@@ -934,7 +934,7 @@ write_codex_config() {
|
|
|
934
934
|
# Tag the client so telemetry can attribute traffic to Codex vs other CLIs
|
|
935
935
|
# that share the same router key. The router otherwise has to guess from
|
|
936
936
|
# User-Agent.
|
|
937
|
-
headers_parts="${headers_parts}, \"X-App\" = \"codex\", \"X-Weave-Codex-Native-Model-Pin\" = \"1\""
|
|
937
|
+
headers_parts="${headers_parts}, \"X-App\" = \"codex\", \"X-Weave-Codex-Native-Model-Pin\" = \"1\", \"X-Weave-Codex-Model-Catalog\" = \"1\""
|
|
938
938
|
# No strategy header: pinning one here freezes installed clients on whatever
|
|
939
939
|
# policy was current at install time, so a deployment-default change never
|
|
940
940
|
# reaches them. Every endpoint, hosted or self-hosted, uses its own default.
|
|
@@ -1041,6 +1041,7 @@ name = "Weave Router"
|
|
|
1041
1041
|
base_url = "${esc_url}/v1"
|
|
1042
1042
|
wire_api = "responses"
|
|
1043
1043
|
requires_openai_auth = true
|
|
1044
|
+
model_catalog_url = "${esc_url}/v1/codex/models"
|
|
1044
1045
|
${headers_line}
|
|
1045
1046
|
${hook_block}
|
|
1046
1047
|
${WEAVE_CODEX_END_MARKER}
|
|
@@ -2027,7 +2028,7 @@ fi
|
|
|
2027
2028
|
# Claude Desktop is configured through a local proxy service, not a settings
|
|
2028
2029
|
# file, so there is nothing to toggle or scope per repo.
|
|
2029
2030
|
if [ "$target" = "claude-desktop" ] && [ "$mode" != "install" ] && [ "$mode" != "update" ]; then
|
|
2030
|
-
err "Toggle verbs (off/on/status) aren't supported for --claude-desktop.
|
|
2031
|
+
err "Toggle verbs (off/on/status) aren't supported for --claude-desktop. Run 'npx $npm_package_name --uninstall --claude-desktop' to go direct."
|
|
2031
2032
|
exit 2
|
|
2032
2033
|
fi
|
|
2033
2034
|
if [ "$target" = "claude-desktop" ] && [ "$scope" = "project" ]; then
|
|
@@ -3010,6 +3011,59 @@ gitignore_add() {
|
|
|
3010
3011
|
fi
|
|
3011
3012
|
}
|
|
3012
3013
|
|
|
3014
|
+
# Claude Code sends a picker model ID verbatim (minus [1m], which it turns into
|
|
3015
|
+
# the 1M-context beta); the router routes only weave-auto and serves every other
|
|
3016
|
+
# model as-is (X-Weave-Model-Passthrough).
|
|
3017
|
+
CLAUDE_WEAVE_AUTO_OPTION='{"model":"weave-auto[1m]","label":"Weave Auto","description":"Weave picks the best model for each turn","behavesAs":"claude-opus-5-5"}'
|
|
3018
|
+
# shellcheck disable=SC2016 # jq variables, expanded by jq.
|
|
3019
|
+
CLAUDE_WEAVE_AUTO_ADD_JQ='.modelPicker = ((.modelPicker // {}) | .options = ([$option] + ((.options // []) | map(select(.model != "weave-auto" and .model != "weave-auto[1m]")))))
|
|
3020
|
+
| (if $set_model == "force" then .model = $option.model | (if (.env | type) == "object" then .env |= del(.ANTHROPIC_MODEL) else . end)
|
|
3021
|
+
elif ($set_model == "true" and (has("model") | not)) or .model == "weave-auto" then .model = $option.model else . end)'
|
|
3022
|
+
CLAUDE_WEAVE_AUTO_STRIP_JQ='(if (.model == "weave-auto" or .model == "weave-auto[1m]") then del(.model) else . end)
|
|
3023
|
+
| (if (.modelPicker | type) == "object" then
|
|
3024
|
+
.modelPicker.options = ((.modelPicker.options // []) | map(select(.model != "weave-auto" and .model != "weave-auto[1m]")))
|
|
3025
|
+
| (if (.modelPicker.options | length) == 0 then del(.modelPicker.options) else . end)
|
|
3026
|
+
| (if (.modelPicker | length) == 0 then del(.modelPicker) else . end)
|
|
3027
|
+
else . end)'
|
|
3028
|
+
|
|
3029
|
+
# claude_model_unset reports whether no Claude Code settings layer or
|
|
3030
|
+
# ANTHROPIC_MODEL selects a model, so defaulting to Weave Auto overrides nothing.
|
|
3031
|
+
claude_model_unset() {
|
|
3032
|
+
local source
|
|
3033
|
+
[ -z "${ANTHROPIC_MODEL:-}" ] || return 1
|
|
3034
|
+
for source in "$@"; do
|
|
3035
|
+
[ -f "$source" ] || continue
|
|
3036
|
+
if jq -e 'has("model") or (.env.ANTHROPIC_MODEL // "" | length > 0)' "$source" >/dev/null 2>&1; then
|
|
3037
|
+
return 1
|
|
3038
|
+
fi
|
|
3039
|
+
done
|
|
3040
|
+
return 0
|
|
3041
|
+
}
|
|
3042
|
+
|
|
3043
|
+
# claude_passthrough_installed reports whether a settings file already carries
|
|
3044
|
+
# the passthrough header, i.e. this install has been through the Weave Auto rollout.
|
|
3045
|
+
claude_passthrough_installed() {
|
|
3046
|
+
local source
|
|
3047
|
+
for source in "$@"; do
|
|
3048
|
+
[ -f "$source" ] || continue
|
|
3049
|
+
if jq -e '(.env.ANTHROPIC_CUSTOM_HEADERS // "") | test("(^|\\n)X-Weave-Model-Passthrough:")' "$source" >/dev/null 2>&1; then
|
|
3050
|
+
return 0
|
|
3051
|
+
fi
|
|
3052
|
+
done
|
|
3053
|
+
return 1
|
|
3054
|
+
}
|
|
3055
|
+
|
|
3056
|
+
# apply_claude_weave_auto creates $1 when missing and keeps a non-shared
|
|
3057
|
+
# settings file private (mode 600). $2 is "force" (select Weave Auto over any
|
|
3058
|
+
# saved model), "true" (select it only when no model is set) or "false".
|
|
3059
|
+
apply_claude_weave_auto() {
|
|
3060
|
+
local target="$1" set_model="$2" merged
|
|
3061
|
+
[ -f "$target" ] || printf '{}\n' >"$target"
|
|
3062
|
+
merged="$(jq --argjson option "$CLAUDE_WEAVE_AUTO_OPTION" --arg set_model "$set_model" "$CLAUDE_WEAVE_AUTO_ADD_JQ" "$target")"
|
|
3063
|
+
printf '%s\n' "$merged" >"$target"
|
|
3064
|
+
[ "$target" = "$settings_file" ] || chmod 600 "$target"
|
|
3065
|
+
}
|
|
3066
|
+
|
|
3013
3067
|
prepare_claude_context_window() {
|
|
3014
3068
|
context_settings_file="$settings_file"
|
|
3015
3069
|
if [ "$scope" = "project" ] && [ -z "$install_dir" ]; then
|
|
@@ -3142,22 +3196,33 @@ toggle_claude() {
|
|
|
3142
3196
|
# base URL to Anthropic in the local file only — committed settings.json
|
|
3143
3197
|
# is never touched, so this stays out of `git diff`.
|
|
3144
3198
|
if [ -f "$local_settings_file" ]; then
|
|
3145
|
-
jq '{env: (.env // {})}' "$local_settings_file" >"$parked"
|
|
3146
|
-
merged="$(jq '.env = ((.env // {} | del(.ANTHROPIC_CUSTOM_HEADERS)) + {ANTHROPIC_BASE_URL: "https://api.anthropic.com"})' "$local_settings_file")"
|
|
3199
|
+
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")"
|
|
3147
3201
|
else
|
|
3148
3202
|
printf '{"env":{}}\n' >"$parked"
|
|
3149
3203
|
merged='{"env":{"ANTHROPIC_BASE_URL":"https://api.anthropic.com"}}'
|
|
3150
3204
|
fi
|
|
3151
3205
|
printf '%s\n' "$merged" >"$local_settings_file"
|
|
3206
|
+
# A Weave Auto default inherited from user scope would reach Anthropic
|
|
3207
|
+
# directly, so pin a real model locally while off.
|
|
3208
|
+
local inherited_model
|
|
3209
|
+
inherited_model="$(json_get "$settings_file" '.model')"
|
|
3210
|
+
[ -n "$inherited_model" ] || inherited_model="$(json_get "$HOME/.claude/settings.json" '.model')"
|
|
3211
|
+
if [ -z "$(json_get "$local_settings_file" '.model')" ] && { [ "$inherited_model" = "weave-auto" ] || [ "$inherited_model" = "weave-auto[1m]" ]; }; then
|
|
3212
|
+
merged="$(jq '.model = "opus"' "$local_settings_file")"
|
|
3213
|
+
printf '%s\n' "$merged" >"$local_settings_file"
|
|
3214
|
+
merged="$(jq '.off_pin = "opus"' "$parked")"
|
|
3215
|
+
printf '%s\n' "$merged" >"$parked"
|
|
3216
|
+
fi
|
|
3152
3217
|
chmod 600 "$local_settings_file" "$parked"
|
|
3153
3218
|
gitignore_add ".claude/.weave-parked.json"
|
|
3154
3219
|
else
|
|
3155
3220
|
# Park just the router-owned env keys, then strip them so Claude Code
|
|
3156
3221
|
# falls back to its own Anthropic login.
|
|
3157
|
-
jq '{env: ((.env // {}) | {ANTHROPIC_BASE_URL, ANTHROPIC_CUSTOM_HEADERS, ENABLE_TOOL_SEARCH} | with_entries(select(.value != null)))}' "$settings_file" >"$parked"
|
|
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"
|
|
3158
3223
|
chmod 600 "$parked"
|
|
3159
3224
|
merged="$(jq '(.env // {}) |= del(.ANTHROPIC_BASE_URL, .ANTHROPIC_CUSTOM_HEADERS, .ENABLE_TOOL_SEARCH)
|
|
3160
|
-
| (if (.env // {} | length) == 0 then del(.env) else . end)' "$settings_file")"
|
|
3225
|
+
| (if (.env // {} | length) == 0 then del(.env) else . end) | '"$CLAUDE_WEAVE_AUTO_STRIP_JQ" "$settings_file")"
|
|
3161
3226
|
printf '%s\n' "$merged" >"$settings_file"
|
|
3162
3227
|
fi
|
|
3163
3228
|
ok "Claude Code is ${C_BOLD}off${C_RESET} (direct to Anthropic). Restart Claude Code for it to take effect."
|
|
@@ -3224,6 +3289,17 @@ toggle_claude() {
|
|
|
3224
3289
|
merged="$(jq --argjson p "$parked_env" '.env = (((.env // {}) | del(.ANTHROPIC_BASE_URL)) + $p)' "$active")"
|
|
3225
3290
|
printf '%s\n' "$merged" >"$active"
|
|
3226
3291
|
[ "$proj" = "true" ] && chmod 600 "$active"
|
|
3292
|
+
local off_pin
|
|
3293
|
+
off_pin="$(jq -r '.off_pin // empty' "$parked")"
|
|
3294
|
+
if [ -n "$off_pin" ] && [ "$(json_get "$active" '.model')" = "$off_pin" ]; then
|
|
3295
|
+
merged="$(jq 'del(.model)' "$active")"
|
|
3296
|
+
printf '%s\n' "$merged" >"$active"
|
|
3297
|
+
fi
|
|
3298
|
+
if [ "$(jq -r '.weave_auto_selected // false' "$parked")" = "true" ]; then
|
|
3299
|
+
apply_claude_weave_auto "$active" true
|
|
3300
|
+
else
|
|
3301
|
+
apply_claude_weave_auto "$active" false
|
|
3302
|
+
fi
|
|
3227
3303
|
apply_claude_context_window on "$active"
|
|
3228
3304
|
rm -f "$parked"
|
|
3229
3305
|
ok "Claude Code is ${C_BOLD}on${C_RESET} (routing through the Weave Router). Restart Claude Code for it to take effect."
|
|
@@ -4545,6 +4621,22 @@ if [ "$mode" = "update" ] && [ "$base_url_explicit" != "true" ]; then
|
|
|
4545
4621
|
fi
|
|
4546
4622
|
fi
|
|
4547
4623
|
|
|
4624
|
+
# Claude Desktop re-installs keep the proxy's endpoint, and a first install
|
|
4625
|
+
# takes the endpoint and key from the Claude Code CLI install (or the copy
|
|
4626
|
+
# `off --claude` parked): a key is only admitted on its own serving fleet, so
|
|
4627
|
+
# the hosted default can reject it.
|
|
4628
|
+
desktop_cli_key=""
|
|
4629
|
+
if [ "$target" = "claude-desktop" ] && [ "$base_url_explicit" != "true" ] && [ -z "${WEAVE_ROUTER_URL:-}" ]; then
|
|
4630
|
+
installed_base="$(resolve_installed_endpoint)"
|
|
4631
|
+
for cli_settings_file in "$settings_base/.claude/settings.json" "$settings_base/.claude/.weave-parked.json"; do
|
|
4632
|
+
[ -z "$installed_base" ] || break
|
|
4633
|
+
router_shaped_url "$(json_get "$cli_settings_file" '.env.ANTHROPIC_BASE_URL')" || continue
|
|
4634
|
+
installed_base="$(json_get "$cli_settings_file" '.env.ANTHROPIC_BASE_URL')"
|
|
4635
|
+
desktop_cli_key="$(read_claude_key "$cli_settings_file")"
|
|
4636
|
+
done
|
|
4637
|
+
[ -z "$installed_base" ] || base_url="$(strip_trailing_slashes "$installed_base")"
|
|
4638
|
+
fi
|
|
4639
|
+
|
|
4548
4640
|
if [ "$mode" = "install" ]; then
|
|
4549
4641
|
[ "$quiet" = "true" ] || info "scope=${C_BOLD}${scope}${C_RESET} target=${C_BOLD}${target}${C_RESET} base_url=${C_BOLD}${base_url}${C_RESET}"
|
|
4550
4642
|
else
|
|
@@ -4582,6 +4674,7 @@ prompt_for_key() {
|
|
|
4582
4674
|
api_key=""
|
|
4583
4675
|
installed_key=""
|
|
4584
4676
|
[ "$rotate_key" = "true" ] || installed_key="$(read_installed_key)"
|
|
4677
|
+
[ -n "$installed_key" ] || [ "$rotate_key" = "true" ] || installed_key="$desktop_cli_key"
|
|
4585
4678
|
|
|
4586
4679
|
if [ -n "${WEAVE_ROUTER_KEY:-}" ]; then
|
|
4587
4680
|
api_key="$WEAVE_ROUTER_KEY"
|
|
@@ -6267,7 +6360,7 @@ desktop_shim_source() {
|
|
|
6267
6360
|
# write_desktop_shim_certs makes a CA that may only sign api.anthropic.com,
|
|
6268
6361
|
# signs one leaf with it, then deletes the CA key so nothing else can ever be
|
|
6269
6362
|
# minted from the CA that Claude Code is told to trust. Re-runs keep a still
|
|
6270
|
-
# valid pair, because
|
|
6363
|
+
# valid pair, because the OS already trusts ca.pem.
|
|
6271
6364
|
write_desktop_shim_certs() {
|
|
6272
6365
|
local dir="$desktop_shim_dir" tmp
|
|
6273
6366
|
# An organization can hand every machine the same IT-made pair instead, and
|
|
@@ -7042,6 +7135,9 @@ weave_hidden_gate() {
|
|
|
7042
7135
|
local cache="$cache_dir/display-settings${script_slug}"
|
|
7043
7136
|
local ttl="${WEAVE_DISPLAY_SETTINGS_TTL_SECONDS:-3600}"
|
|
7044
7137
|
|
|
7138
|
+
# Linked plans that need a fresh login, from the last successful refresh.
|
|
7139
|
+
weave_disconnected_plans="$(cat "$cache.plans" 2>/dev/null)"
|
|
7140
|
+
|
|
7045
7141
|
local now mtime fresh="false"
|
|
7046
7142
|
now="$(date +%s 2>/dev/null)" || now=0
|
|
7047
7143
|
if [ -f "$cache" ]; then
|
|
@@ -7141,6 +7237,8 @@ weave_hidden_gate() {
|
|
|
7141
7237
|
else
|
|
7142
7238
|
printf '0' >"$tmp" 2>/dev/null && mv "$tmp" "$cache" 2>/dev/null
|
|
7143
7239
|
fi
|
|
7240
|
+
plans="$(printf '%s' "$body" | jq -r '[.disconnected_plans[]? | select(type == "string" and test("^[a-z]+$"))] | join(" ")' 2>/dev/null)"
|
|
7241
|
+
printf '%s' "$plans" >"$tmp" 2>/dev/null && mv "$tmp" "$cache.plans" 2>/dev/null
|
|
7144
7242
|
rm -f "$tmp" 2>/dev/null
|
|
7145
7243
|
) >/dev/null 2>&1 &
|
|
7146
7244
|
disown 2>/dev/null || true
|
|
@@ -7750,7 +7848,8 @@ brand=$'\033[38;2;255;108;71mWEAVE ROUTER\033[0m'
|
|
|
7750
7848
|
# saving.
|
|
7751
7849
|
short_model() { printf '%s' "${1#claude-}"; }
|
|
7752
7850
|
picked=""
|
|
7753
|
-
|
|
7851
|
+
# Weave Auto is a routing choice, not a model, so only the served model is shown.
|
|
7852
|
+
if [[ -n "$selected_display" && "$selected_display" != "?" && "$requested_norm" != "weave-auto" ]]; then
|
|
7754
7853
|
picked="$(short_model "$requested_norm")"
|
|
7755
7854
|
fi
|
|
7756
7855
|
status_text=""
|
|
@@ -7781,6 +7880,27 @@ if [[ "$has_pin_record" == "true" ]]; then
|
|
|
7781
7880
|
status_text="$status_text · last pin: $last_pin_model"
|
|
7782
7881
|
fi
|
|
7783
7882
|
|
|
7883
|
+
# Point the reconnect command at this install: a bare login reads the
|
|
7884
|
+
# user-scope config, which a project or --dir install doesn't use.
|
|
7885
|
+
weave_login_scope=""
|
|
7886
|
+
if [ -n "${weave_disconnected_plans:-}" ]; then
|
|
7887
|
+
weave_sl_dir="$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" 2>/dev/null && pwd)"
|
|
7888
|
+
case "$weave_sl_dir" in
|
|
7889
|
+
*/.claude)
|
|
7890
|
+
weave_login_scope=" --dir $(printf '%q' "${weave_sl_dir%/.claude}")"
|
|
7891
|
+
if grep -q 'X-Weave-Router-Key' "$weave_sl_dir/settings.local.json" 2>/dev/null; then
|
|
7892
|
+
weave_login_scope=" --scope project$weave_login_scope"
|
|
7893
|
+
fi
|
|
7894
|
+
;;
|
|
7895
|
+
esac
|
|
7896
|
+
fi
|
|
7897
|
+
for weave_plan in ${weave_disconnected_plans:-}; do
|
|
7898
|
+
case "$weave_plan" in
|
|
7899
|
+
claude) status_text="$status_text · Claude plan disconnected: run npx @weave-os/router login claude$weave_login_scope" ;;
|
|
7900
|
+
codex) status_text="$status_text · Codex plan disconnected: run npx @weave-os/router login codex$weave_login_scope" ;;
|
|
7901
|
+
esac
|
|
7902
|
+
done
|
|
7903
|
+
|
|
7784
7904
|
# /router-status reads this back through the prompt hook, so it can answer
|
|
7785
7905
|
# without a model turn.
|
|
7786
7906
|
weave_cache_status_line() {
|
|
@@ -7824,6 +7944,15 @@ trap '_spin_cleanup; rm -f "$tmp_patch"' EXIT INT TERM HUP
|
|
|
7824
7944
|
write_claude_settings() {
|
|
7825
7945
|
local block_key="$1"
|
|
7826
7946
|
prepare_claude_context_window
|
|
7947
|
+
# Before passthrough every model was routed, so a model saved back then was
|
|
7948
|
+
# never a pin. Move those installs (and new ones) to Weave Auto once; later
|
|
7949
|
+
# updates keep whatever the user picks.
|
|
7950
|
+
# --context-window pins its own [1m] model, so it is never overridden.
|
|
7951
|
+
local weave_auto_rollout="true"
|
|
7952
|
+
if [ -n "$context_window" ] || [ -f "$settings_dir/.weave-context-window.json" ] \
|
|
7953
|
+
|| claude_passthrough_installed "$context_settings_file" "$settings_file"; then
|
|
7954
|
+
weave_auto_rollout="false"
|
|
7955
|
+
fi
|
|
7827
7956
|
|
|
7828
7957
|
# Claude Code splits ANTHROPIC_CUSTOM_HEADERS on newlines, so multiple headers
|
|
7829
7958
|
# ride in the same env var separated by \n. Append identity headers alongside
|
|
@@ -7837,7 +7966,7 @@ write_claude_settings() {
|
|
|
7837
7966
|
if [ -n "$user_name" ]; then
|
|
7838
7967
|
custom_headers="$custom_headers"$'\n'"X-Weave-User-Name: $user_name"
|
|
7839
7968
|
fi
|
|
7840
|
-
custom_headers="$custom_headers"$'\n'"X-App: claude-code"
|
|
7969
|
+
custom_headers="$custom_headers"$'\n'"X-App: claude-code"$'\n'"X-Weave-Model-Passthrough: 1"
|
|
7841
7970
|
|
|
7842
7971
|
# Setting ANTHROPIC_BASE_URL makes Claude Code treat us as non-first-party.
|
|
7843
7972
|
# Force tool-search deferral to match first-party Claude Code; "auto" can inline
|
|
@@ -7928,6 +8057,16 @@ write_claude_settings() {
|
|
|
7928
8057
|
chmod 600 "$local_settings_file"
|
|
7929
8058
|
ok "Router key header written to $local_settings_file"
|
|
7930
8059
|
fi
|
|
8060
|
+
local weave_auto_default="false"
|
|
8061
|
+
if [ "$weave_auto_rollout" = "true" ]; then
|
|
8062
|
+
weave_auto_default="force"
|
|
8063
|
+
if [ -n "${ANTHROPIC_MODEL:-}" ]; then
|
|
8064
|
+
warn "ANTHROPIC_MODEL=$ANTHROPIC_MODEL in your shell pins that model and skips Weave routing. Unset it to use Weave Auto."
|
|
8065
|
+
fi
|
|
8066
|
+
elif claude_model_unset "$context_settings_file" "$settings_file" "$HOME/.claude/settings.json"; then
|
|
8067
|
+
weave_auto_default="true"
|
|
8068
|
+
fi
|
|
8069
|
+
apply_claude_weave_auto "$context_settings_file" "$weave_auto_default"
|
|
7931
8070
|
context_window_action="install"
|
|
7932
8071
|
if [ "$mode" = "update" ] && [ ! -f "$settings_dir/.weave-parked.json" ]; then
|
|
7933
8072
|
context_window_action="update"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@weave-os/router",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.33",
|
|
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",
|
package/uninstall.sh
CHANGED
|
@@ -151,6 +151,13 @@ EOF
|
|
|
151
151
|
target="claude"
|
|
152
152
|
|
|
153
153
|
CLAUDE_STATUSLINE_MARKER="# Claude Code statusline for the Weave Router."
|
|
154
|
+
# Mirrors install.sh: removes only the Weave Auto picker row and default.
|
|
155
|
+
CLAUDE_WEAVE_AUTO_STRIP_JQ='(if (.model == "weave-auto" or .model == "weave-auto[1m]") then del(.model) else . end)
|
|
156
|
+
| (if (.modelPicker | type) == "object" then
|
|
157
|
+
.modelPicker.options = ((.modelPicker.options // []) | map(select(.model != "weave-auto" and .model != "weave-auto[1m]")))
|
|
158
|
+
| (if (.modelPicker.options | length) == 0 then del(.modelPicker.options) else . end)
|
|
159
|
+
| (if (.modelPicker | length) == 0 then del(.modelPicker) else . end)
|
|
160
|
+
else . end)'
|
|
154
161
|
|
|
155
162
|
err() { printf "\033[31merror:\033[0m %s\n" "$*" >&2; }
|
|
156
163
|
warn() { printf "\033[33mwarning:\033[0m %s\n" "$*" >&2; }
|
|
@@ -1410,7 +1417,7 @@ if [ -f "$settings_file" ]; then
|
|
|
1410
1417
|
# delete `statusLine` / `apiKeyHelper` when they point at scripts this
|
|
1411
1418
|
# installer used in older versions. Otherwise an unrelated user-configured
|
|
1412
1419
|
# statusLine or apiKeyHelper would be silently clobbered.
|
|
1413
|
-
cleaned="$(jq --arg statusline_setting_owned "$statusline_setting_owned" '
|
|
1420
|
+
cleaned="$(jq --arg statusline_setting_owned "$statusline_setting_owned" "$CLAUDE_WEAVE_AUTO_STRIP_JQ"' |
|
|
1414
1421
|
if .env then
|
|
1415
1422
|
.env |= (del(.ANTHROPIC_BASE_URL, .ANTHROPIC_AUTH_TOKEN, .ANTHROPIC_CUSTOM_HEADERS, .ENABLE_TOOL_SEARCH))
|
|
1416
1423
|
| (if (.env | length) == 0 then del(.env) else . end)
|
|
@@ -1441,7 +1448,7 @@ if [ -n "$local_settings_file" ] && [ -f "$local_settings_file" ]; then
|
|
|
1441
1448
|
# (the off path overrides it to Anthropic in the local file). Project installs
|
|
1442
1449
|
# also keep WEAVE_ROUTER_BASE_URL here as a private endpoint marker beside the
|
|
1443
1450
|
# router key; scrub both so uninstall fully reverts the local config.
|
|
1444
|
-
cleaned="$(jq '
|
|
1451
|
+
cleaned="$(jq "$CLAUDE_WEAVE_AUTO_STRIP_JQ"' |
|
|
1445
1452
|
if .env then
|
|
1446
1453
|
.env |= (del(.ANTHROPIC_BASE_URL, .ANTHROPIC_AUTH_TOKEN, .ANTHROPIC_CUSTOM_HEADERS, .ENABLE_TOOL_SEARCH, .WEAVE_ROUTER_BASE_URL))
|
|
1447
1454
|
| (if (.env | length) == 0 then del(.env) else . end)
|
package/windows.js
CHANGED
|
@@ -216,6 +216,21 @@ async function ensureProjectFilesPrivate(root, target) {
|
|
|
216
216
|
return trackedProjectPaths;
|
|
217
217
|
}
|
|
218
218
|
|
|
219
|
+
// Claude Code sends a picker model ID verbatim (minus [1m], which it turns into
|
|
220
|
+
// the 1M-context beta); the router routes only weave-auto and serves every other
|
|
221
|
+
// model as-is (X-Weave-Model-Passthrough).
|
|
222
|
+
const claudeWeaveAutoModel = "weave-auto[1m]";
|
|
223
|
+
const isClaudeWeaveAuto = (model) => model === "weave-auto" || model === claudeWeaveAutoModel;
|
|
224
|
+
const claudeWeaveAutoOption = { model: claudeWeaveAutoModel, label: "Weave Auto", description: "Weave picks the best model for each turn", behavesAs: "claude-opus-5-5" };
|
|
225
|
+
|
|
226
|
+
function stripClaudeWeaveAuto(layer) {
|
|
227
|
+
if (isClaudeWeaveAuto(layer.model)) delete layer.model;
|
|
228
|
+
if (!layer.modelPicker || typeof layer.modelPicker !== "object") return;
|
|
229
|
+
layer.modelPicker.options = (layer.modelPicker.options || []).filter((option) => !isClaudeWeaveAuto(option?.model));
|
|
230
|
+
if (!layer.modelPicker.options.length) delete layer.modelPicker.options;
|
|
231
|
+
if (!Object.keys(layer.modelPicker).length) delete layer.modelPicker;
|
|
232
|
+
}
|
|
233
|
+
|
|
219
234
|
function installClaude(paths, baseUrl, key, email, attribution) {
|
|
220
235
|
const settings = readJson(paths.config);
|
|
221
236
|
// Same rule as install.sh: an install without our attribution block is an opt-out that reinstalls keep.
|
|
@@ -231,11 +246,15 @@ function installClaude(paths, baseUrl, key, email, attribution) {
|
|
|
231
246
|
};
|
|
232
247
|
state.installedBaseUrl = baseUrl;
|
|
233
248
|
const customHeaders = localSettings?.env?.ANTHROPIC_CUSTOM_HEADERS ?? settings.env?.ANTHROPIC_CUSTOM_HEADERS ?? "";
|
|
234
|
-
|
|
249
|
+
// Before passthrough every model was routed, so a saved model was never a pin:
|
|
250
|
+
// move those installs (and new ones) to Weave Auto once, then keep the user's picks.
|
|
251
|
+
const weaveAutoRollout = ![settings, localSettings].some((layer) => /^X-Weave-Model-Passthrough:/im.test(layer?.env?.ANTHROPIC_CUSTOM_HEADERS || ""));
|
|
252
|
+
const previousHeaders = customHeaders.split("\n").filter((header) => !/^X-(?:Weave-Router-Key|Weave-User-Email|Weave-User-Name|Weave-Model-Passthrough|App):/i.test(header));
|
|
235
253
|
const routerHeaders = [
|
|
236
254
|
`X-Weave-Router-Key: ${key}`,
|
|
237
255
|
...(email ? [`X-Weave-User-Email: ${email}`] : []),
|
|
238
256
|
"X-App: claude-code",
|
|
257
|
+
"X-Weave-Model-Passthrough: 1",
|
|
239
258
|
];
|
|
240
259
|
settings.env ||= {};
|
|
241
260
|
settings.env.ANTHROPIC_BASE_URL = baseUrl;
|
|
@@ -247,6 +266,14 @@ function installClaude(paths, baseUrl, key, email, attribution) {
|
|
|
247
266
|
settings.env.ANTHROPIC_CUSTOM_HEADERS = [...previousHeaders, ...routerHeaders].filter(Boolean).join("\n");
|
|
248
267
|
}
|
|
249
268
|
settings.env.ENABLE_TOOL_SEARCH = "true";
|
|
269
|
+
const modelSettings = localSettings || settings;
|
|
270
|
+
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
|
+
modelSettings.modelPicker = { ...(modelSettings.modelPicker || {}) };
|
|
272
|
+
modelSettings.modelPicker.options = [claudeWeaveAutoOption, ...(modelSettings.modelPicker.options || []).filter((option) => !isClaudeWeaveAuto(option?.model))];
|
|
273
|
+
if (weaveAutoRollout) {
|
|
274
|
+
modelSettings.model = claudeWeaveAutoModel;
|
|
275
|
+
if (modelSettings.env) delete modelSettings.env.ANTHROPIC_MODEL;
|
|
276
|
+
} else if (modelUnset || modelSettings.model === "weave-auto") modelSettings.model = claudeWeaveAutoModel;
|
|
250
277
|
if (attribution && (ownsAttribution || (settings.attribution == null && !optedOutOfAttribution))) {
|
|
251
278
|
settings.attribution = { ...claudeAttribution, ...settings.attribution, commit: claudeAttribution.commit };
|
|
252
279
|
} else if (!attribution && ownsAttribution) {
|
|
@@ -274,11 +301,13 @@ function installCodex(paths, baseUrl, key, email) {
|
|
|
274
301
|
base_url: `${baseUrl}/v1`,
|
|
275
302
|
wire_api: "responses",
|
|
276
303
|
requires_openai_auth: true,
|
|
304
|
+
model_catalog_url: `${baseUrl}/v1/codex/models`,
|
|
277
305
|
http_headers: {
|
|
278
306
|
"X-Weave-Router-Key": key,
|
|
279
307
|
...(email ? { "X-Weave-User-Email": email } : {}),
|
|
280
308
|
"X-App": "codex",
|
|
281
309
|
"X-Weave-Codex-Native-Model-Pin": "1",
|
|
310
|
+
"X-Weave-Codex-Model-Catalog": "1",
|
|
282
311
|
},
|
|
283
312
|
};
|
|
284
313
|
writeToml(paths.config, settings);
|
|
@@ -363,8 +392,9 @@ function uninstall(paths, target) {
|
|
|
363
392
|
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;
|
|
364
393
|
restoreField(settings.env, "ANTHROPIC_BASE_URL", state.env?.ANTHROPIC_BASE_URL, state.installedBaseUrl || settings.env?.ANTHROPIC_BASE_URL);
|
|
365
394
|
restoreField(settings.env, "ENABLE_TOOL_SEARCH", state.env?.ENABLE_TOOL_SEARCH, "true");
|
|
395
|
+
for (const layer of [settings, localSettings]) if (layer) stripClaudeWeaveAuto(layer);
|
|
366
396
|
const customHeaders = (headerBlock, originalAppHeaders) => {
|
|
367
|
-
const preservedHeaders = (headerBlock || "").split("\n").filter((header) => !/^X-Weave-(?:Router-Key|User-Email|User-Name):/i.test(header) && !/^X-App:\s*claude-code\s*$/i.test(header));
|
|
397
|
+
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));
|
|
368
398
|
if (!preservedHeaders.some((header) => /^X-App:/i.test(header))) preservedHeaders.push(...(originalAppHeaders || []));
|
|
369
399
|
return preservedHeaders.filter(Boolean).join("\n");
|
|
370
400
|
};
|