@weave-os/router 0.2.29 → 0.2.31

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/uninstall.sh CHANGED
@@ -1,8 +1,9 @@
1
1
  #!/usr/bin/env bash
2
2
  #
3
- # Weave Router uninstaller for Claude Code, Codex, opencode, and pi.
3
+ # Weave Router uninstaller for Claude Code, Codex, opencode, pi, and GitHub Copilot CLI.
4
4
  #
5
- # Default target is Claude Code: removes the env vars, statusLine, and local
5
+ # Without a client flag, every client with Weave Router config is uninstalled
6
+ # in turn. --claude removes the env vars, statusLine, and local
6
7
  # router auth that install.sh added; leaves the rest of settings.json
7
8
  # untouched. Pass --codex to strip the managed [model_providers.weave]
8
9
  # block (and the matching top-level `model_provider`) from Codex's
@@ -14,10 +15,12 @@
14
15
  # weave defaults, and remove the router key file.
15
16
  #
16
17
  # Usage:
17
- # npx @workweave/router --uninstall # Claude Code, user scope
18
+ # npx @workweave/router --uninstall # every configured client, user scope
19
+ # npx @workweave/router --uninstall --claude # Claude Code only
18
20
  # npx @workweave/router --uninstall --codex # Codex, user scope
19
21
  # npx @workweave/router --uninstall --opencode # opencode, user scope
20
22
  # npx @workweave/router --uninstall --pi # pi, user scope
23
+ # npx @workweave/router --uninstall --copilot # GitHub Copilot CLI (providers.json, skills)
21
24
  # npx @workweave/router --uninstall --scope project # run inside the repo
22
25
  # npx @workweave/router --uninstall --dir /tmp/test # --dir alone (user scope, .weave/)
23
26
  # npx @workweave/router --uninstall --scope project --dir /tmp # --dir + project scope (.claude/)
@@ -44,6 +47,7 @@ WEAVE_REGISTRY_DATA=$(cat <<'WEAVE_REGISTRY_EOF'
44
47
  # canonical|aliases|capability|claude|codex|opencode|pi|cursor|adapter
45
48
  # aliases are comma-separated; client columns are yes/no. adapter is the native asset kind.
46
49
  force-model|fm|prompt|yes|yes|yes|yes|manual|command,skill
50
+ force-parent||prompt|yes|yes|yes|yes|manual|command,skill
47
51
  unforce-model|ufm|prompt|yes|yes|yes|yes|manual|command,skill
48
52
  router-feedback|rf|prompt|yes|yes|yes|no|manual|command,skill
49
53
  router-off||local-toggle|yes|yes|no|no|manual|command,skill
@@ -204,6 +208,17 @@ weave_command_router_owned() {
204
208
  return 1
205
209
  }
206
210
 
211
+ # Git Bash rewrites $HOME's /c/... form to C:/... in arguments to native
212
+ # executables such as jq.exe, so the stored command can use either form.
213
+ statusline_commands_match() {
214
+ local first_mixed second_mixed
215
+ [ "$1" = "$2" ] && return 0
216
+ command -v cygpath >/dev/null 2>&1 || return 1
217
+ first_mixed="$(cygpath -m -- "$1" 2>/dev/null)" && [ -n "$first_mixed" ] || return 1
218
+ second_mixed="$(cygpath -m -- "$2" 2>/dev/null)" && [ -n "$second_mixed" ] || return 1
219
+ [ "$first_mixed" = "$second_mixed" ]
220
+ }
221
+
207
222
  # claude_statusline_router_owned reports whether a settings entry points at the
208
223
  # router's statusline. Existing scripts prove ownership with the marker; when a
209
224
  # script is missing, the adjacent ownership marker proves that the router wrote
@@ -212,7 +227,7 @@ claude_statusline_router_owned() {
212
227
  local settings_path="$1" expected_command="$2" script_path="$3" ownership_marker_path="$4" configured_command
213
228
  [ -f "$settings_path" ] || return 1
214
229
  configured_command="$(jq -r '.statusLine.command // empty' "$settings_path" 2>/dev/null || true)"
215
- [ "$configured_command" = "$expected_command" ] || return 1
230
+ statusline_commands_match "$configured_command" "$expected_command" || return 1
216
231
  if [ -f "$script_path" ]; then
217
232
  if grep -Fq "$CLAUDE_STATUSLINE_MARKER" "$script_path" 2>/dev/null; then
218
233
  return 0
@@ -223,6 +238,8 @@ claude_statusline_router_owned() {
223
238
  && grep -Fq "$CLAUDE_STATUSLINE_MARKER" "$ownership_marker_path"
224
239
  }
225
240
 
241
+ uninstall_args=("$@")
242
+ target_explicit="false"
226
243
  while [ $# -gt 0 ]; do
227
244
  case "$1" in
228
245
  --scope)
@@ -235,20 +252,23 @@ while [ $# -gt 0 ]; do
235
252
  [ -n "$install_dir" ] || { err "--dir requires a path."; exit 2; }
236
253
  ;;
237
254
  --codex)
238
- target="codex"; shift
255
+ target="codex"; target_explicit="true"; shift
239
256
  ;;
240
257
  --opencode)
241
- target="opencode"; shift
258
+ target="opencode"; target_explicit="true"; shift
242
259
  ;;
243
260
  --pi)
244
- target="pi"; shift
261
+ target="pi"; target_explicit="true"; shift
262
+ ;;
263
+ --copilot)
264
+ target="copilot"; target_explicit="true"; shift
245
265
  ;;
246
266
  --claude)
247
267
  # No-op selector for symmetry with --codex / --opencode and install.sh's
248
268
  # --claude. Lets `./install.sh --uninstall --claude` (which forwards
249
269
  # remaining args here) succeed instead of hitting the unknown-flag
250
270
  # catch-all.
251
- target="claude"; shift
271
+ target="claude"; target_explicit="true"; shift
252
272
  ;;
253
273
  -h|--help)
254
274
  # awk avoids GNU `head -n -<N>` (rejected by BSD head on macOS).
@@ -261,7 +281,66 @@ while [ $# -gt 0 ]; do
261
281
  esac
262
282
  done
263
283
 
264
- if { [ "$target" = "claude" ] || [ "$target" = "opencode" ] || [ "$target" = "pi" ]; } && ! command -v jq >/dev/null 2>&1; then
284
+ # skip_if_not_installed ends a child of a bare --uninstall quietly (exit 3)
285
+ # unless config $1 has a line matching ERE $2 or any further path exists. A
286
+ # client that is installed still needs jq, checked here rather than up front.
287
+ skip_if_not_installed() {
288
+ [ -n "${WEAVE_UNINSTALL_ALL_CHILD:-}" ] || return 0
289
+ local config="$1" pattern="$2" installed="false" extra
290
+ shift 2
291
+ [ -f "$config" ] && grep -Eq -- "$pattern" "$config" && installed="true"
292
+ for extra in "$@"; do [ -e "$extra" ] && installed="true"; done
293
+ [ "$installed" = "true" ] || exit 3
294
+ [ "$target" = "codex" ] || command -v jq >/dev/null 2>&1 || { err "jq is required for the $target uninstall path."; exit 1; }
295
+ }
296
+
297
+ client_label() {
298
+ case "$1" in
299
+ claude) printf 'Claude Code' ;;
300
+ codex) printf 'Codex' ;;
301
+ copilot) printf 'Copilot CLI' ;;
302
+ *) printf '%s' "$1" ;;
303
+ esac
304
+ }
305
+
306
+ # A bare --uninstall removes Weave Router from every client it configured. Each
307
+ # client runs as its own child so its path stays exactly the --<client> one. A
308
+ # piped run with no recoverable source keeps the old Claude Code-only default.
309
+ uninstall_self="$0"
310
+ [ -f "$uninstall_self" ] || uninstall_self=""
311
+ if [ "$target_explicit" = "false" ] && [ -z "${WEAVE_UNINSTALL_ALL_CHILD:-}" ] \
312
+ && { [ -n "$uninstall_self" ] || [ -n "${BASH_EXECUTION_STRING:-}" ]; }; then
313
+ uninstall_self_tmp=""
314
+ if [ -z "$uninstall_self" ]; then
315
+ uninstall_self_tmp="$(mktemp -t weave-uninstall.XXXXXX)"
316
+ printf '%s\n' "$BASH_EXECUTION_STRING" >"$uninstall_self_tmp"
317
+ uninstall_self="$uninstall_self_tmp"
318
+ fi
319
+ removed=""
320
+ failed=""
321
+ for client in claude codex opencode pi copilot; do
322
+ child_status=0
323
+ WEAVE_UNINSTALL_ALL_CHILD=1 bash "$uninstall_self" "${uninstall_args[@]+"${uninstall_args[@]}"}" "--$client" || child_status=$?
324
+ case "$child_status" in
325
+ 0) removed="${removed:+$removed, }$(client_label "$client")" ;;
326
+ 3) ;;
327
+ *) failed="${failed:+$failed, }$(client_label "$client")" ;;
328
+ esac
329
+ done
330
+ [ -z "$uninstall_self_tmp" ] || rm -f "$uninstall_self_tmp"
331
+ printf '\n'
332
+ if [ -z "$removed" ] && [ -z "$failed" ]; then
333
+ info "Weave Router isn't configured for Claude Code, Codex, opencode, pi or Copilot CLI here (scope=$scope); nothing to remove."
334
+ fi
335
+ [ -z "$removed" ] || ok "Removed Weave Router from: $removed."
336
+ if [ -n "$failed" ]; then
337
+ err "Weave Router may still be routing: $failed. See the errors above."
338
+ exit 1
339
+ fi
340
+ exit 0
341
+ fi
342
+
343
+ if [ -z "${WEAVE_UNINSTALL_ALL_CHILD:-}" ] && { [ "$target" = "claude" ] || [ "$target" = "opencode" ] || [ "$target" = "pi" ] || [ "$target" = "copilot" ]; } && ! command -v jq >/dev/null 2>&1; then
265
344
  err "jq is required for the $target uninstall path."
266
345
  exit 1
267
346
  fi
@@ -279,7 +358,8 @@ fi
279
358
  # install, and never supplies a key; a checkout-supplied endpoint never
280
359
  # receives one (same gates as install.sh's key_source_is_own and
281
360
  # models_endpoint_is_trusted).
282
- HOSTED_BASE_URL="https://router.workweave.ai"
361
+ HOSTED_BASE_URL="https://router.weaveos.com"
362
+ LEGACY_HOSTED_BASE_URL="https://router.workweave.ai"
283
363
  ROUTER_KEY_HEADER="X-Weave-Router-Key"
284
364
 
285
365
  uninstall_json_get() {
@@ -360,7 +440,7 @@ report_claude_uninstall_event() {
360
440
  done
361
441
  [ -n "$key" ] || return 0
362
442
  local trusted="false"
363
- if [ "$endpoint" = "${HOSTED_BASE_URL%/}" ] || [ "$base_src" = "$key_src" ]; then
443
+ if [ "$endpoint" = "${HOSTED_BASE_URL%/}" ] || [ "$endpoint" = "${LEGACY_HOSTED_BASE_URL%/}" ] || [ "$base_src" = "$key_src" ]; then
364
444
  trusted="true"
365
445
  elif [ -n "$local_settings_file" ] && [ -f "$local_settings_file" ] && [ ! -L "$local_settings_file" ]; then
366
446
  marked="$(uninstall_json_get "$local_settings_file" '.env.WEAVE_ROUTER_BASE_URL')"
@@ -657,6 +737,7 @@ if [ "$target" = "opencode" ]; then
657
737
  refuse_if_symlink "$opencode_dir"
658
738
  fi
659
739
  opencode_config_file="$opencode_dir/opencode.json"
740
+ skip_if_not_installed "$opencode_config_file" '"weave(-claude|-codex)?"' "$opencode_dir/.weave-parked.json"
660
741
  opencode_parked="$opencode_dir/.weave-parked.json"
661
742
  opencode_direct_model=""
662
743
  refuse_if_symlink "$opencode_config_file"
@@ -786,6 +867,74 @@ EOF
786
867
  exit 0
787
868
  fi
788
869
 
870
+ # ---------- copilot uninstall path ----------
871
+
872
+ if [ "$target" = "copilot" ]; then
873
+ # Mirrors install.sh: user scope only; --dir is a throwaway COPILOT_HOME.
874
+ if [ -n "$install_dir" ]; then
875
+ install_dir="$(cd "$install_dir" 2>/dev/null && pwd || echo "$install_dir")"
876
+ copilot_dir="$install_dir/.copilot"
877
+ else
878
+ copilot_dir="${COPILOT_HOME:-$HOME/.copilot}"
879
+ fi
880
+ copilot_providers_file="$copilot_dir/providers.json"
881
+ copilot_settings_file="$copilot_dir/settings.json"
882
+ copilot_parked_file="$copilot_dir/.weave-parked.json"
883
+ for path in "$copilot_dir" "$copilot_providers_file" "$copilot_settings_file" "$copilot_parked_file"; do
884
+ refuse_if_symlink "$path"
885
+ done
886
+ skip_if_not_installed "$copilot_providers_file" '"name": *"weave"' "$copilot_parked_file"
887
+
888
+ if [ -f "$copilot_providers_file" ]; then
889
+ report_uninstall_event copilot \
890
+ "$(jq -r '[(.providers // [])[] | select(.name == "weave") | .baseUrl // empty][0] // empty' "$copilot_providers_file" 2>/dev/null | sed 's#/v1$##')" \
891
+ "$(jq -r '[(.providers // [])[] | select(.name == "weave") | .headers["X-Weave-Router-Key"] // empty][0] // empty' "$copilot_providers_file" 2>/dev/null)" || true
892
+ cleaned="$(jq '
893
+ .providers = [(.providers // [])[] | select(.name != "weave")]
894
+ | .models = [(.models // [])[] | select(.provider != "weave")]
895
+ ' "$copilot_providers_file")"
896
+ if [ "$(printf '%s' "$cleaned" | jq '(.providers | length) + (.models | length) + (del(.providers, .models) | length)')" = "0" ]; then
897
+ rm -f "$copilot_providers_file"
898
+ ok "Removed empty $copilot_providers_file"
899
+ else
900
+ printf '%s\n' "$cleaned" >"$copilot_providers_file"
901
+ chmod 600 "$copilot_providers_file"
902
+ ok "Removed the weave provider from $copilot_providers_file"
903
+ fi
904
+ else
905
+ info "No Copilot CLI providers.json at $copilot_providers_file (already uninstalled?)"
906
+ fi
907
+
908
+ if [ -f "$copilot_settings_file" ]; then
909
+ direct_model=""
910
+ [ -f "$copilot_parked_file" ] && direct_model="$(jq -r '.direct_model // empty' "$copilot_parked_file" 2>/dev/null || true)"
911
+ cleaned="$(jq --arg direct "$direct_model" '
912
+ if ((.model // "") | startswith("weave/"))
913
+ then (if $direct != "" then .model = $direct else del(.model) end)
914
+ else . end
915
+ ' "$copilot_settings_file")"
916
+ printf '%s\n' "$cleaned" >"$copilot_settings_file"
917
+ ok "Restored Copilot CLI default model in $copilot_settings_file${direct_model:+ ($direct_model)}"
918
+ fi
919
+ rm -f "$copilot_parked_file"
920
+
921
+ # Only remove skills that still carry our ownership marker.
922
+ if [ -d "$copilot_dir/skills" ] && [ ! -L "$copilot_dir/skills" ]; then
923
+ for skill_dir in "$copilot_dir"/skills/*/; do
924
+ [ -d "$skill_dir" ] || continue
925
+ skill_dir="${skill_dir%/}"
926
+ name="${skill_dir##*/}"
927
+ [ -L "$skill_dir" ] && continue
928
+ if [ ! -f "$skill_dir/SKILL.md" ] || [ -L "$skill_dir/SKILL.md" ]; then continue; fi
929
+ grep -Fq "<!-- weave-router managed $name skill -->" "$skill_dir/SKILL.md" || continue
930
+ rm -rf "$skill_dir"
931
+ done
932
+ rmdir "$copilot_dir/skills" 2>/dev/null || true
933
+ ok "Removed Weave Router Copilot skills"
934
+ fi
935
+ exit 0
936
+ fi
937
+
789
938
  # ---------- pi uninstall path ----------
790
939
 
791
940
  if [ "$target" = "pi" ]; then
@@ -837,6 +986,7 @@ if [ "$target" = "pi" ]; then
837
986
  refuse_if_symlink "$pi_settings_file"
838
987
  refuse_if_symlink "$pi_key_file"
839
988
 
989
+ skip_if_not_installed "$pi_models_file" '"weave"'
840
990
  report_pi_uninstall_event "$pi_models_file" "$pi_key_file" || true
841
991
  # models.json: drop provider.weave; remove the file if nothing else remains.
842
992
  # Other providers/models the user added are preserved.
@@ -954,6 +1104,7 @@ if [ "$target" = "codex" ]; then
954
1104
  # exits before strip_codex_block, so one symlinked helper left the config
955
1105
  # wired to a router the uninstall had just been asked to remove.
956
1106
 
1107
+ skip_if_not_installed "$codex_config_file" 'model_providers.weave'
957
1108
  report_codex_uninstall_event "$codex_config_file" || true
958
1109
  if [ -f "$codex_config_file" ]; then
959
1110
  strip_codex_block "$codex_config_file"
@@ -1147,6 +1298,8 @@ else
1147
1298
  refuse_if_symlink "$statusline_ownership_file"
1148
1299
  fi
1149
1300
 
1301
+ skip_if_not_installed "$settings_file" 'ANTHROPIC_BASE_URL|Weave Router|cc-statusline' \
1302
+ "$(dirname "$settings_file")/.weave-parked.json" "$(dirname "$settings_file")/.weave-context-window.json" "$statusline_file"
1150
1303
  statusline_file_owned="false"
1151
1304
  statusline_setting_owned="false"
1152
1305
  context_state_file="$(dirname "$settings_file")/.weave-context-window.json"
@@ -1176,6 +1329,7 @@ fi
1176
1329
 
1177
1330
  report_claude_uninstall_event || true
1178
1331
 
1332
+
1179
1333
  if [ -f "$settings_file" ]; then
1180
1334
  # Only remove keys we actually installed: scrub our env vars, and only
1181
1335
  # delete `statusLine` / `apiKeyHelper` when they point at scripts this
@@ -1187,12 +1341,18 @@ if [ -f "$settings_file" ]; then
1187
1341
  | (if (.env | length) == 0 then del(.env) else . end)
1188
1342
  else . end
1189
1343
  | (if $statusline_setting_owned == "true" then del(.statusLine) else . end)
1344
+ | (if (.hooks.UserPromptSubmit | type) == "array" then
1345
+ .hooks.UserPromptSubmit |= (map(if (.hooks | type) == "array" then .hooks |= map(select((.command // "" | tostring | test("cc-statusline\\.sh\"? --prompt-hook( |$)")) | not)) else . end) | map(select((.hooks | type) != "array" or (.hooks | length) > 0)))
1346
+ | (if (.hooks.UserPromptSubmit | length) == 0 then del(.hooks.UserPromptSubmit) else . end)
1347
+ | (if (.hooks | length) == 0 then del(.hooks) else . end)
1348
+ else . end)
1190
1349
  | (if (.apiKeyHelper // "" | tostring | endswith("weave-key.sh"))
1191
1350
  then del(.apiKeyHelper) else . end)
1192
1351
  | (if ((.attribution.commit == "Co-Authored-By: Weave Router <router@weaveos.com>"
1193
1352
  or .attribution.commit == "Co-Authored-By: Weave Router <router@workweave.ai>"
1194
1353
  or .attribution.commit == "Co-Authored-By: Weave Router <noreply@workweave.ai>")
1195
- and .attribution.pr == "🤖 Generated with [Weave Router](https://router.workweave.ai)")
1354
+ and (.attribution.pr == "🤖 Generated with [Weave Router](https://router.weaveos.com)"
1355
+ or .attribution.pr == "🤖 Generated with [Weave Router](https://router.workweave.ai)"))
1196
1356
  then del(.attribution) else . end)
1197
1357
  ' "$settings_file")"
1198
1358
  printf '%s\n' "$cleaned" >"$settings_file"