@weave-os/router 0.2.22 → 0.2.23
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 +1 -0
- package/install.sh +90 -10
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -21,6 +21,7 @@ npx @weave-os/router --scope project # per-repo install, commit settings.j
|
|
|
21
21
|
npx @weave-os/router --local # self-hosted via docker-compose (localhost:8080)
|
|
22
22
|
npx @weave-os/router --base-url https://router.acme.internal
|
|
23
23
|
npx @weave-os/router --email you@example.com # set identity without prompting
|
|
24
|
+
npx @weave-os/router --claude --return-url https://app.example.com/onboarding # continue after a verified install
|
|
24
25
|
npx @weave-os/router --non-interactive # reads $WEAVE_ROUTER_KEY, no prompts (defaults to claude)
|
|
25
26
|
```
|
|
26
27
|
|
package/install.sh
CHANGED
|
@@ -53,8 +53,9 @@
|
|
|
53
53
|
# npx @weave-os/router --local # local router on localhost:8080
|
|
54
54
|
# npx @weave-os/router --base-url http://localhost:8080 # self-hosted, custom port
|
|
55
55
|
# npx @weave-os/router --email you@example.com # set the router identity email without prompting
|
|
56
|
+
# npx @weave-os/router --return-url https://example.com # open a URL after a verified install
|
|
56
57
|
# npx @weave-os/router --non-interactive # require WEAVE_ROUTER_KEY env var (defaults target to claude)
|
|
57
|
-
# npx @weave-os/router --quiet # suppress banner, ping check, and trailing tips
|
|
58
|
+
# npx @weave-os/router --quiet # suppress banner, ping check, and trailing tips (return-url still verifies)
|
|
58
59
|
# npx @weave-os/router --rotate-key # ignore the installed key and prompt for a new one
|
|
59
60
|
# npx @weave-os/router --uninstall # remove a previous install (delegates to uninstall.sh)
|
|
60
61
|
#
|
|
@@ -121,6 +122,7 @@ base_url=""
|
|
|
121
122
|
base_url_explicit="false"
|
|
122
123
|
email=""
|
|
123
124
|
email_explicit="false"
|
|
125
|
+
return_url=""
|
|
124
126
|
non_interactive="false"
|
|
125
127
|
quiet="false"
|
|
126
128
|
router_key_header="X-Weave-Router-Key"
|
|
@@ -164,6 +166,8 @@ rotate_key="false"
|
|
|
164
166
|
# Where $api_key came from: env | disk | prompt. Drives the fallback re-prompt
|
|
165
167
|
# when /validate rejects a key we read back off disk.
|
|
166
168
|
api_key_source=""
|
|
169
|
+
# Set by verify_install; a return URL is opened only after both probes pass.
|
|
170
|
+
install_verification_succeeded="false"
|
|
167
171
|
|
|
168
172
|
# ---------- helpers ----------
|
|
169
173
|
|
|
@@ -1391,6 +1395,14 @@ while [ $# -gt 0 ]; do
|
|
|
1391
1395
|
[ -n "$email" ] || { err "--email requires a value."; exit 2; }
|
|
1392
1396
|
email_explicit="true"
|
|
1393
1397
|
;;
|
|
1398
|
+
--return-url)
|
|
1399
|
+
return_url="${2:-}"; shift 2
|
|
1400
|
+
[ -n "$return_url" ] || { err "--return-url requires a value."; exit 2; }
|
|
1401
|
+
case "$return_url" in
|
|
1402
|
+
http://*|https://*) ;;
|
|
1403
|
+
*) err "--return-url must be an http:// or https:// URL."; exit 2 ;;
|
|
1404
|
+
esac
|
|
1405
|
+
;;
|
|
1394
1406
|
--local)
|
|
1395
1407
|
# Shorthand for local dev: localhost:8080 (matches `wv mr` / `make dev` default PORT).
|
|
1396
1408
|
base_url="http://localhost:8080"
|
|
@@ -1504,6 +1516,11 @@ if [ "$mode" = "setup" ]; then
|
|
|
1504
1516
|
[ "$non_interactive" = "true" ] && setup_args+=(--non-interactive)
|
|
1505
1517
|
[ "$base_url_explicit" = "true" ] && setup_args+=(--base-url "$base_url")
|
|
1506
1518
|
[ "$email_explicit" = "true" ] && setup_args+=(--email "$email")
|
|
1519
|
+
if [ -n "$return_url" ] && [ "$setup_claude" = "true" ] && [ "$setup_codex" = "true" ]; then
|
|
1520
|
+
err "--return-url with setup requires a single target: use setup --claude or setup --codex."
|
|
1521
|
+
exit 2
|
|
1522
|
+
fi
|
|
1523
|
+
[ -n "$return_url" ] && setup_args+=(--return-url "$return_url")
|
|
1507
1524
|
[ -n "$install_dir" ] && setup_args+=(--dir "$install_dir")
|
|
1508
1525
|
[ "$quiet" = "true" ] && setup_args+=(--quiet)
|
|
1509
1526
|
[ "$rotate_key" = "true" ] && setup_args+=(--rotate-key)
|
|
@@ -1512,6 +1529,11 @@ if [ "$mode" = "setup" ]; then
|
|
|
1512
1529
|
exit 0
|
|
1513
1530
|
fi
|
|
1514
1531
|
|
|
1532
|
+
if [ -n "$return_url" ] && [ "$mode" != "install" ]; then
|
|
1533
|
+
err "--return-url is supported only for install (or setup with one explicit target)."
|
|
1534
|
+
exit 2
|
|
1535
|
+
fi
|
|
1536
|
+
|
|
1515
1537
|
# --lsp is a pi-extension feature, so it implies the pi target; combining it
|
|
1516
1538
|
# with another explicit target is a contradiction, not a preference.
|
|
1517
1539
|
if [ -n "$lsp_langs" ]; then
|
|
@@ -2494,7 +2516,7 @@ apply_claude_context_window() {
|
|
|
2494
2516
|
local action="$1" active="$2" state="$settings_dir/.weave-context-window.json" merged tmp
|
|
2495
2517
|
refuse_if_symlink "$state"
|
|
2496
2518
|
[ -f "$active" ] || return 0
|
|
2497
|
-
if [
|
|
2519
|
+
if [ -n "$context_window" ]; then
|
|
2498
2520
|
tmp="$(mktemp "$settings_dir/.weave-context.XXXXXX")"
|
|
2499
2521
|
jq --arg managed "$context_managed_model" '{had_model: has("model"), original: .model, managed: $managed}' "$active" >"$tmp"
|
|
2500
2522
|
chmod 600 "$tmp"
|
|
@@ -2502,13 +2524,13 @@ apply_claude_context_window() {
|
|
|
2502
2524
|
merged="$(jq --arg model "$context_managed_model" '.model = $model' "$active")"
|
|
2503
2525
|
else
|
|
2504
2526
|
[ -f "$state" ] || return 0
|
|
2505
|
-
merged="$(jq --slurpfile state "$state" --arg action "$action" '
|
|
2527
|
+
merged="$(jq --slurpfile state "$state" --arg action "$action" --arg context_window "$context_window" '
|
|
2506
2528
|
$state[0] as $s |
|
|
2507
2529
|
if $action == "off" then
|
|
2508
2530
|
if .model == $s.managed then
|
|
2509
2531
|
if $s.had_model then .model = $s.original else del(.model) end
|
|
2510
2532
|
else . end
|
|
2511
|
-
elif has("model") == $s.had_model and .model == $s.original then .model = $s.managed
|
|
2533
|
+
elif ($action == "install" or $action == "on" or $context_window != "") and has("model") == $s.had_model and .model == $s.original then .model = $s.managed
|
|
2512
2534
|
else . end
|
|
2513
2535
|
' "$active")"
|
|
2514
2536
|
fi
|
|
@@ -2516,7 +2538,7 @@ apply_claude_context_window() {
|
|
|
2516
2538
|
printf '%s\n' "$merged" >"$tmp"
|
|
2517
2539
|
chmod 600 "$tmp"
|
|
2518
2540
|
mv "$tmp" "$active"
|
|
2519
|
-
if [
|
|
2541
|
+
if [ -n "$context_window" ]; then
|
|
2520
2542
|
ok "Claude Code model set to $context_managed_model; automatic compaction stays enabled. Restart Claude Code."
|
|
2521
2543
|
if [ "$scope" = "project" ] && [ -z "$install_dir" ]; then
|
|
2522
2544
|
gitignore_add ".claude/.weave-context-window.json"
|
|
@@ -3185,6 +3207,47 @@ oauth_base64url() {
|
|
|
3185
3207
|
openssl base64 -A | tr '+/' '-_' | tr -d '='
|
|
3186
3208
|
}
|
|
3187
3209
|
|
|
3210
|
+
# open_url_in_browser asks the operating system to open a URL with the user's
|
|
3211
|
+
# default browser. Keep this best-effort: a successful install must not be
|
|
3212
|
+
# rolled back just because a headless shell has no browser opener available.
|
|
3213
|
+
open_url_in_browser() {
|
|
3214
|
+
local url="$1" os
|
|
3215
|
+
os="$(uname -s 2>/dev/null || printf '')"
|
|
3216
|
+
case "$os" in
|
|
3217
|
+
Darwin*)
|
|
3218
|
+
command -v open >/dev/null 2>&1 || return 1
|
|
3219
|
+
open "$url" >/dev/null 2>&1
|
|
3220
|
+
;;
|
|
3221
|
+
MINGW*|MSYS*|CYGWIN*)
|
|
3222
|
+
# explorer.exe is a direct process launch; cmd.exe /c start would parse
|
|
3223
|
+
# URL query separators such as '&' as shell syntax. Its exit status is
|
|
3224
|
+
# not meaningful: an already-running shell commonly returns 1 after
|
|
3225
|
+
# handing the URL off.
|
|
3226
|
+
command -v explorer.exe >/dev/null 2>&1 || return 1
|
|
3227
|
+
explorer.exe "$url" >/dev/null 2>&1 || true
|
|
3228
|
+
return 0
|
|
3229
|
+
;;
|
|
3230
|
+
*)
|
|
3231
|
+
command -v xdg-open >/dev/null 2>&1 || return 1
|
|
3232
|
+
xdg-open "$url" >/dev/null 2>&1
|
|
3233
|
+
;;
|
|
3234
|
+
esac
|
|
3235
|
+
}
|
|
3236
|
+
|
|
3237
|
+
open_return_url_if_verified() {
|
|
3238
|
+
[ "$mode" = "install" ] || return 0
|
|
3239
|
+
[ -n "$return_url" ] || return 0
|
|
3240
|
+
if [ "${install_verification_succeeded:-false}" != "true" ]; then
|
|
3241
|
+
warn "Skipping return URL because router verification did not complete successfully."
|
|
3242
|
+
return 0
|
|
3243
|
+
fi
|
|
3244
|
+
if open_url_in_browser "$return_url"; then
|
|
3245
|
+
info "Opened return URL in your browser: $return_url"
|
|
3246
|
+
else
|
|
3247
|
+
warn "Install succeeded, but no default-browser opener was available. Open this URL to continue: $return_url"
|
|
3248
|
+
fi
|
|
3249
|
+
}
|
|
3250
|
+
|
|
3188
3251
|
open_oauth_url() {
|
|
3189
3252
|
local url="$1"
|
|
3190
3253
|
if command -v open >/dev/null 2>&1; then
|
|
@@ -3910,15 +3973,25 @@ rewrite_installed_key() {
|
|
|
3910
3973
|
}
|
|
3911
3974
|
|
|
3912
3975
|
verify_install() {
|
|
3913
|
-
|
|
3914
|
-
|
|
3976
|
+
local health_verified="false"
|
|
3977
|
+
install_verification_succeeded="false"
|
|
3978
|
+
|
|
3979
|
+
# --quiet normally skips the health probe, but a return URL is only safe to
|
|
3980
|
+
# open after both probes have actually run and passed.
|
|
3981
|
+
if [ "$quiet" != "true" ] || [ -n "$return_url" ]; then
|
|
3982
|
+
if spin "Pinging $base_url/health" curl -fsS --max-time 5 "$base_url/health"; then
|
|
3983
|
+
health_verified="true"
|
|
3984
|
+
else
|
|
3915
3985
|
warn "Could not reach $base_url/health within 5s. Settings are written; verify the router is running."
|
|
3916
3986
|
fi
|
|
3917
3987
|
fi
|
|
3918
3988
|
|
|
3919
3989
|
[ -n "$api_key" ] || return 0
|
|
3920
3990
|
|
|
3921
|
-
spin "Validating API key" validate_key
|
|
3991
|
+
if spin "Validating API key" validate_key; then
|
|
3992
|
+
[ "$health_verified" = "true" ] && install_verification_succeeded="true"
|
|
3993
|
+
return 0
|
|
3994
|
+
fi
|
|
3922
3995
|
|
|
3923
3996
|
# A key we read back off disk can have been revoked or rotated since it was
|
|
3924
3997
|
# installed, and reusing it silently would leave a broken install behind
|
|
@@ -3931,7 +4004,9 @@ verify_install() {
|
|
|
3931
4004
|
warn "The router key already installed was rejected (revoked or rotated)."
|
|
3932
4005
|
prompt_for_key
|
|
3933
4006
|
rewrite_installed_key "$api_key"
|
|
3934
|
-
if
|
|
4007
|
+
if spin "Validating API key" validate_key; then
|
|
4008
|
+
[ "$health_verified" = "true" ] && install_verification_succeeded="true"
|
|
4009
|
+
else
|
|
3935
4010
|
warn "Router rejected the API key (check it matches the dashboard at $base_url)."
|
|
3936
4011
|
fi
|
|
3937
4012
|
return 0
|
|
@@ -3966,6 +4041,7 @@ announce_done() {
|
|
|
3966
4041
|
fi
|
|
3967
4042
|
printf "%s✓%s %s%sWeave Router installed for %s.%s\n" \
|
|
3968
4043
|
"$C_GREEN" "$C_RESET" "$C_BOLD" "$C_BRAND" "$1" "$C_RESET"
|
|
4044
|
+
open_return_url_if_verified
|
|
3969
4045
|
}
|
|
3970
4046
|
|
|
3971
4047
|
# ---------- codex install path (dispatch + exit before the Claude-only writes) ----------
|
|
@@ -5964,7 +6040,11 @@ write_claude_settings() {
|
|
|
5964
6040
|
chmod 600 "$local_settings_file"
|
|
5965
6041
|
ok "Router key header written to $local_settings_file"
|
|
5966
6042
|
fi
|
|
5967
|
-
|
|
6043
|
+
context_window_action="install"
|
|
6044
|
+
if [ "$mode" = "update" ] && [ ! -f "$settings_dir/.weave-parked.json" ]; then
|
|
6045
|
+
context_window_action="update"
|
|
6046
|
+
fi
|
|
6047
|
+
apply_claude_context_window "$context_window_action" "$context_settings_file"
|
|
5968
6048
|
}
|
|
5969
6049
|
|
|
5970
6050
|
# write_claude_settings rewrites the full router config live, so a parked
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@weave-os/router",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.23",
|
|
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",
|