@weave-os/router 0.2.24 → 0.2.25
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 +10 -6
- package/install.sh +148 -88
- package/opencode-weave/README.md +32 -63
- package/opencode-weave/package.json +1 -1
- package/opencode-weave/src/index.ts +13 -624
- package/package.json +1 -1
- package/uninstall.sh +179 -11
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@weave-os/router",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.25",
|
|
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
|
@@ -265,6 +265,171 @@ if { [ "$target" = "claude" ] || [ "$target" = "opencode" ] || [ "$target" = "pi
|
|
|
265
265
|
exit 1
|
|
266
266
|
fi
|
|
267
267
|
|
|
268
|
+
# ---------- lifecycle report ----------
|
|
269
|
+
#
|
|
270
|
+
# report_uninstall_event tells this install's router that the uninstall is
|
|
271
|
+
# happening, so it can log and export a lifecycle event. It runs before the
|
|
272
|
+
# key and config are removed (afterwards there is nothing left to
|
|
273
|
+
# authenticate with) and is strictly best-effort: the POST is detached with a
|
|
274
|
+
# short timeout, output discarded, and no failure changes the uninstall.
|
|
275
|
+
# uninstall.sh is served standalone, so the config readers install.sh already
|
|
276
|
+
# has are reduced here to the one field each: the endpoint and key of the
|
|
277
|
+
# managed provider block. A file git tracks is a checkout's, not this user's
|
|
278
|
+
# install, and never supplies a key; a checkout-supplied endpoint never
|
|
279
|
+
# receives one (same gates as install.sh's key_source_is_own and
|
|
280
|
+
# models_endpoint_is_trusted).
|
|
281
|
+
HOSTED_BASE_URL="https://router.workweave.ai"
|
|
282
|
+
ROUTER_KEY_HEADER="X-Weave-Router-Key"
|
|
283
|
+
|
|
284
|
+
uninstall_json_get() {
|
|
285
|
+
[ -f "$1" ] || return 0
|
|
286
|
+
jq -r "${2} // empty" "$1" 2>/dev/null || true
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
# uninstall_file_is_own mirrors key_source_is_own: only a project-scoped file
|
|
290
|
+
# is reachable by a repo, and one git tracks is not this user's install.
|
|
291
|
+
uninstall_file_is_own() {
|
|
292
|
+
local f="$1"
|
|
293
|
+
[ -f "$f" ] || return 1
|
|
294
|
+
[ -L "$f" ] && return 1
|
|
295
|
+
[ "$scope" = "project" ] && [ -z "$install_dir" ] || return 0
|
|
296
|
+
command -v git >/dev/null 2>&1 || return 1
|
|
297
|
+
git -C "$(dirname "$f")" ls-files --error-unmatch -- "$f" >/dev/null 2>&1 && return 1
|
|
298
|
+
return 0
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
uninstall_file_is_tracked() {
|
|
302
|
+
command -v git >/dev/null 2>&1 || return 1
|
|
303
|
+
git -C "$(dirname "$1")" ls-files --error-unmatch -- "$1" >/dev/null 2>&1
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
# uninstall_claude_key_from FILE prints the router key header value out of a
|
|
307
|
+
# Claude Code settings-shaped file ({"env":{"ANTHROPIC_CUSTOM_HEADERS":…}}).
|
|
308
|
+
uninstall_claude_key_from() {
|
|
309
|
+
uninstall_json_get "$1" '.env.ANTHROPIC_CUSTOM_HEADERS' \
|
|
310
|
+
| sed -n "s/^[[:space:]]*${ROUTER_KEY_HEADER}:[[:space:]]*//p" | head -n 1 | tr -d '[:space:]'
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
# report_uninstall_event HARNESS ENDPOINT KEY — fire the detached POST. The
|
|
314
|
+
# whole body runs in a subshell with errexit off so no setup failure can
|
|
315
|
+
# escape into the uninstall that still has files to remove.
|
|
316
|
+
report_uninstall_event() {
|
|
317
|
+
local harness="$1" endpoint="${2%/}" key="$3"
|
|
318
|
+
(
|
|
319
|
+
set +e
|
|
320
|
+
headers="" body=""
|
|
321
|
+
[ -n "$endpoint" ] && [ -n "$key" ] || exit 0
|
|
322
|
+
command -v curl >/dev/null 2>&1 || exit 0
|
|
323
|
+
headers="$(mktemp)" || exit 0
|
|
324
|
+
chmod 600 "$headers" || { rm -f "$headers"; exit 0; }
|
|
325
|
+
printf '%s: %s\n' "$ROUTER_KEY_HEADER" "$key" >"$headers" || { rm -f "$headers"; exit 0; }
|
|
326
|
+
body="$(printf '{"action":"uninstall","harness":"%s"}' "$harness")"
|
|
327
|
+
(
|
|
328
|
+
trap 'rm -f "$headers"' EXIT
|
|
329
|
+
curl -sS --max-time 2 -X POST -H 'Content-Type: application/json' \
|
|
330
|
+
--header "@$headers" --data-binary "$body" -o /dev/null \
|
|
331
|
+
"$endpoint/v1/client-events"
|
|
332
|
+
) >/dev/null 2>&1 </dev/null &
|
|
333
|
+
) >/dev/null 2>&1 || true
|
|
334
|
+
return 0
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
# report_claude_uninstall_event reads the endpoint and key the way install.sh's
|
|
338
|
+
# resolve_installed_endpoint / read_installed_key do for Claude Code: the
|
|
339
|
+
# parked sidecar first (while toggled off it holds both), then the settings
|
|
340
|
+
# files. Endpoint and key from the same file are self-consistent; otherwise the
|
|
341
|
+
# endpoint must be the hosted default, vouched for by the private
|
|
342
|
+
# WEAVE_ROUTER_BASE_URL marker beside the key, or live in a file git does not
|
|
343
|
+
# track.
|
|
344
|
+
report_claude_uninstall_event() {
|
|
345
|
+
local parked candidate endpoint="" base_src="" key="" key_src="" found marked
|
|
346
|
+
parked="$(dirname "$settings_file")/.weave-parked.json"
|
|
347
|
+
for candidate in "$parked" "$settings_file" "$local_settings_file"; do
|
|
348
|
+
if [ -z "$candidate" ] || [ ! -f "$candidate" ] || [ -L "$candidate" ]; then continue; fi
|
|
349
|
+
found="$(uninstall_json_get "$candidate" '.env.ANTHROPIC_BASE_URL')"
|
|
350
|
+
case "$found" in ""|https://api.anthropic.com*|http://api.anthropic.com*) continue ;; esac
|
|
351
|
+
endpoint="${found%/}"; base_src="$candidate"
|
|
352
|
+
break
|
|
353
|
+
done
|
|
354
|
+
[ -n "$endpoint" ] || return 0
|
|
355
|
+
for candidate in "$local_settings_file" "$settings_file" "$parked"; do
|
|
356
|
+
if [ -z "$candidate" ] || [ ! -f "$candidate" ] || [ -L "$candidate" ]; then continue; fi
|
|
357
|
+
key="$(uninstall_claude_key_from "$candidate")"
|
|
358
|
+
[ -n "$key" ] && { key_src="$candidate"; break; }
|
|
359
|
+
done
|
|
360
|
+
[ -n "$key" ] || return 0
|
|
361
|
+
local trusted="false"
|
|
362
|
+
if [ "$endpoint" = "${HOSTED_BASE_URL%/}" ] || [ "$base_src" = "$key_src" ]; then
|
|
363
|
+
trusted="true"
|
|
364
|
+
elif [ -n "$local_settings_file" ] && [ -f "$local_settings_file" ] && [ ! -L "$local_settings_file" ]; then
|
|
365
|
+
marked="$(uninstall_json_get "$local_settings_file" '.env.WEAVE_ROUTER_BASE_URL')"
|
|
366
|
+
if [ "${marked%/}" = "$endpoint" ]; then
|
|
367
|
+
uninstall_file_is_tracked "$local_settings_file" || trusted="true"
|
|
368
|
+
fi
|
|
369
|
+
fi
|
|
370
|
+
if [ "$trusted" != "true" ]; then
|
|
371
|
+
command -v git >/dev/null 2>&1 || return 0
|
|
372
|
+
uninstall_file_is_tracked "$base_src" && return 0
|
|
373
|
+
fi
|
|
374
|
+
report_uninstall_event claude_code "$endpoint" "$key"
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
# report_codex_uninstall_event reads base_url and the key header out of the
|
|
378
|
+
# [model_providers.weave] table wherever it sits (Codex's serializer drops the
|
|
379
|
+
# managed markers and may move the header into a subtable).
|
|
380
|
+
report_codex_uninstall_event() {
|
|
381
|
+
local f="$1" endpoint key
|
|
382
|
+
uninstall_file_is_own "$f" || return 0
|
|
383
|
+
endpoint="$(awk '
|
|
384
|
+
/^[[:space:]]*\[/ {
|
|
385
|
+
in_provider = ($0 ~ /^[[:space:]]*\[[[:space:]]*model_providers[[:space:]]*\.[[:space:]]*weave[[:space:]]*\][[:space:]]*(#.*)?$/)
|
|
386
|
+
next
|
|
387
|
+
}
|
|
388
|
+
in_provider && match($0, /^[[:space:]]*base_url[[:space:]]*=[[:space:]]*"[^"]*"/) {
|
|
389
|
+
line = substr($0, RSTART, RLENGTH)
|
|
390
|
+
sub(/^.*=[[:space:]]*"/, "", line)
|
|
391
|
+
sub(/"$/, "", line)
|
|
392
|
+
print line
|
|
393
|
+
exit
|
|
394
|
+
}
|
|
395
|
+
' "$f" 2>/dev/null || true)"
|
|
396
|
+
endpoint="${endpoint%/}"; endpoint="${endpoint%/v1}"
|
|
397
|
+
key="$(awk '
|
|
398
|
+
/^[[:space:]]*\[/ {
|
|
399
|
+
in_provider = ($0 ~ /^[[:space:]]*\[[[:space:]]*model_providers[[:space:]]*\.[[:space:]]*weave[[:space:]]*(\.[^]]*)?\][[:space:]]*(#.*)?$/)
|
|
400
|
+
next
|
|
401
|
+
}
|
|
402
|
+
in_provider && match($0, /"?X-Weave-Router-Key"?[[:space:]]*=[[:space:]]*"[^"]*"/) {
|
|
403
|
+
hdr = substr($0, RSTART, RLENGTH)
|
|
404
|
+
sub(/^.*=[[:space:]]*"/, "", hdr)
|
|
405
|
+
sub(/"$/, "", hdr)
|
|
406
|
+
print hdr
|
|
407
|
+
exit
|
|
408
|
+
}
|
|
409
|
+
' "$f" 2>/dev/null || true)"
|
|
410
|
+
report_uninstall_event codex "$endpoint" "$key"
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
report_opencode_uninstall_event() {
|
|
414
|
+
local f="$1" endpoint key
|
|
415
|
+
uninstall_file_is_own "$f" || return 0
|
|
416
|
+
endpoint="$(uninstall_json_get "$f" '.provider.weave.options.baseURL')"
|
|
417
|
+
endpoint="${endpoint%/}"; endpoint="${endpoint%/v1}"
|
|
418
|
+
key="$(uninstall_json_get "$f" '.provider.weave.options.headers["X-Weave-Router-Key"]')"
|
|
419
|
+
report_uninstall_event opencode "$endpoint" "$key"
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
report_pi_uninstall_event() {
|
|
423
|
+
local models="$1" key_file="$2" endpoint key=""
|
|
424
|
+
uninstall_file_is_own "$models" || return 0
|
|
425
|
+
endpoint="$(uninstall_json_get "$models" '.providers.weave.baseUrl')"
|
|
426
|
+
if uninstall_file_is_own "$key_file"; then
|
|
427
|
+
key="$(tr -d '[:space:]' <"$key_file" 2>/dev/null || true)"
|
|
428
|
+
fi
|
|
429
|
+
[ -n "$key" ] || key="$(uninstall_json_get "$models" '.providers.weave.headers["X-Weave-Router-Key"]')"
|
|
430
|
+
report_uninstall_event pi "$endpoint" "$key"
|
|
431
|
+
}
|
|
432
|
+
|
|
268
433
|
# Markers must stay in sync with install.sh. Keep verbatim.
|
|
269
434
|
WEAVE_CODEX_BEGIN_MARKER="# >>> weave-router managed (do not edit between markers) >>>"
|
|
270
435
|
WEAVE_CODEX_END_MARKER="# <<< weave-router managed <<<"
|
|
@@ -499,18 +664,19 @@ if [ "$target" = "opencode" ]; then
|
|
|
499
664
|
opencode_direct_model="$(jq -r '.direct_model // empty' "$opencode_parked" 2>/dev/null || true)"
|
|
500
665
|
fi
|
|
501
666
|
|
|
502
|
-
#
|
|
503
|
-
#
|
|
504
|
-
# can differ (symlinks, trailing slash) and leave the entry behind.
|
|
667
|
+
# Remove the legacy plugin left by older installers. New installs no longer
|
|
668
|
+
# create it, but uninstall should clean it up when present.
|
|
505
669
|
if [ -d "$opencode_dir" ]; then
|
|
506
670
|
opencode_plugin="$(cd "$opencode_dir" && pwd)/.weave/opencode-weave.ts"
|
|
507
671
|
else
|
|
508
672
|
opencode_plugin="$opencode_dir/.weave/opencode-weave.ts"
|
|
509
673
|
fi
|
|
674
|
+
|
|
675
|
+
report_opencode_uninstall_event "$opencode_config_file" || true
|
|
510
676
|
if [ -f "$opencode_config_file" ]; then
|
|
511
|
-
# Strip every managed provider (`weave`,
|
|
512
|
-
#
|
|
513
|
-
# entry
|
|
677
|
+
# Strip every managed provider (`weave`, `weave-claude`, and the legacy
|
|
678
|
+
# `weave-codex` from pre-upgrade installs), remove the stale legacy plugin
|
|
679
|
+
# entry, and restore the direct model parked during
|
|
514
680
|
# install. Other providers, direct models selected while routing was off,
|
|
515
681
|
# other plugins, and unrelated keys are preserved.
|
|
516
682
|
cleaned="$(jq --arg plugin "$opencode_plugin" --arg direct_model "$opencode_direct_model" '
|
|
@@ -539,9 +705,6 @@ if [ "$target" = "opencode" ]; then
|
|
|
539
705
|
info "No opencode config at $opencode_config_file (already uninstalled?)"
|
|
540
706
|
fi
|
|
541
707
|
|
|
542
|
-
# Drop the bundled subscription plugin (no secrets; the config holds the key,
|
|
543
|
-
# opencode's own auth store holds the ChatGPT/Claude tokens). Remove the
|
|
544
|
-
# .weave/ dir only if it's left empty so we don't clobber an unrelated user dir.
|
|
545
708
|
if [ -f "$opencode_plugin" ]; then
|
|
546
709
|
refuse_if_symlink "$opencode_plugin"
|
|
547
710
|
rm -f "$opencode_plugin"
|
|
@@ -556,7 +719,7 @@ if [ "$target" = "opencode" ]; then
|
|
|
556
719
|
rm -f "$opencode_classifier"
|
|
557
720
|
fi
|
|
558
721
|
rmdir "$opencode_dir/.weave" 2>/dev/null || true
|
|
559
|
-
ok "Removed
|
|
722
|
+
ok "Removed legacy opencode plugin"
|
|
560
723
|
fi
|
|
561
724
|
|
|
562
725
|
# Drop the toggle parked sidecar after its prior model has been restored.
|
|
@@ -665,6 +828,7 @@ if [ "$target" = "pi" ]; then
|
|
|
665
828
|
refuse_if_symlink "$pi_settings_file"
|
|
666
829
|
refuse_if_symlink "$pi_key_file"
|
|
667
830
|
|
|
831
|
+
report_pi_uninstall_event "$pi_models_file" "$pi_key_file" || true
|
|
668
832
|
# models.json: drop provider.weave; remove the file if nothing else remains.
|
|
669
833
|
# Other providers/models the user added are preserved.
|
|
670
834
|
if [ -f "$pi_models_file" ]; then
|
|
@@ -781,6 +945,7 @@ if [ "$target" = "codex" ]; then
|
|
|
781
945
|
# exits before strip_codex_block, so one symlinked helper left the config
|
|
782
946
|
# wired to a router the uninstall had just been asked to remove.
|
|
783
947
|
|
|
948
|
+
report_codex_uninstall_event "$codex_config_file" || true
|
|
784
949
|
if [ -f "$codex_config_file" ]; then
|
|
785
950
|
strip_codex_block "$codex_config_file"
|
|
786
951
|
# If the file now contains only whitespace/comments, leave it: the user
|
|
@@ -1000,6 +1165,8 @@ if claude_statusline_router_owned \
|
|
|
1000
1165
|
statusline_file_owned="true"
|
|
1001
1166
|
fi
|
|
1002
1167
|
|
|
1168
|
+
report_claude_uninstall_event || true
|
|
1169
|
+
|
|
1003
1170
|
if [ -f "$settings_file" ]; then
|
|
1004
1171
|
# Only remove keys we actually installed: scrub our env vars, and only
|
|
1005
1172
|
# delete `statusLine` / `apiKeyHelper` when they point at scripts this
|
|
@@ -1013,7 +1180,8 @@ if [ -f "$settings_file" ]; then
|
|
|
1013
1180
|
| (if $statusline_setting_owned == "true" then del(.statusLine) else . end)
|
|
1014
1181
|
| (if (.apiKeyHelper // "" | tostring | endswith("weave-key.sh"))
|
|
1015
1182
|
then del(.apiKeyHelper) else . end)
|
|
1016
|
-
| (if ((.attribution.commit == "Co-Authored-By: Weave Router <router@
|
|
1183
|
+
| (if ((.attribution.commit == "Co-Authored-By: Weave Router <router@weaveos.com>"
|
|
1184
|
+
or .attribution.commit == "Co-Authored-By: Weave Router <router@workweave.ai>"
|
|
1017
1185
|
or .attribution.commit == "Co-Authored-By: Weave Router <noreply@workweave.ai>")
|
|
1018
1186
|
and .attribution.pr == "🤖 Generated with [Weave Router](https://router.workweave.ai)")
|
|
1019
1187
|
then del(.attribution) else . end)
|