@weave-os/router 0.2.28 → 0.2.30

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,15 +15,18 @@
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/)
24
27
 
25
28
  set -euo pipefail
29
+ export PATH="$PATH:$HOME/.weave/bin"
26
30
 
27
31
  scope="user"
28
32
  scope_explicit="false"
@@ -43,6 +47,7 @@ WEAVE_REGISTRY_DATA=$(cat <<'WEAVE_REGISTRY_EOF'
43
47
  # canonical|aliases|capability|claude|codex|opencode|pi|cursor|adapter
44
48
  # aliases are comma-separated; client columns are yes/no. adapter is the native asset kind.
45
49
  force-model|fm|prompt|yes|yes|yes|yes|manual|command,skill
50
+ force-parent||prompt|yes|yes|yes|yes|manual|command,skill
46
51
  unforce-model|ufm|prompt|yes|yes|yes|yes|manual|command,skill
47
52
  router-feedback|rf|prompt|yes|yes|yes|no|manual|command,skill
48
53
  router-off||local-toggle|yes|yes|no|no|manual|command,skill
@@ -203,6 +208,17 @@ weave_command_router_owned() {
203
208
  return 1
204
209
  }
205
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
+
206
222
  # claude_statusline_router_owned reports whether a settings entry points at the
207
223
  # router's statusline. Existing scripts prove ownership with the marker; when a
208
224
  # script is missing, the adjacent ownership marker proves that the router wrote
@@ -211,7 +227,7 @@ claude_statusline_router_owned() {
211
227
  local settings_path="$1" expected_command="$2" script_path="$3" ownership_marker_path="$4" configured_command
212
228
  [ -f "$settings_path" ] || return 1
213
229
  configured_command="$(jq -r '.statusLine.command // empty' "$settings_path" 2>/dev/null || true)"
214
- [ "$configured_command" = "$expected_command" ] || return 1
230
+ statusline_commands_match "$configured_command" "$expected_command" || return 1
215
231
  if [ -f "$script_path" ]; then
216
232
  if grep -Fq "$CLAUDE_STATUSLINE_MARKER" "$script_path" 2>/dev/null; then
217
233
  return 0
@@ -222,6 +238,8 @@ claude_statusline_router_owned() {
222
238
  && grep -Fq "$CLAUDE_STATUSLINE_MARKER" "$ownership_marker_path"
223
239
  }
224
240
 
241
+ uninstall_args=("$@")
242
+ target_explicit="false"
225
243
  while [ $# -gt 0 ]; do
226
244
  case "$1" in
227
245
  --scope)
@@ -234,20 +252,23 @@ while [ $# -gt 0 ]; do
234
252
  [ -n "$install_dir" ] || { err "--dir requires a path."; exit 2; }
235
253
  ;;
236
254
  --codex)
237
- target="codex"; shift
255
+ target="codex"; target_explicit="true"; shift
238
256
  ;;
239
257
  --opencode)
240
- target="opencode"; shift
258
+ target="opencode"; target_explicit="true"; shift
241
259
  ;;
242
260
  --pi)
243
- target="pi"; shift
261
+ target="pi"; target_explicit="true"; shift
262
+ ;;
263
+ --copilot)
264
+ target="copilot"; target_explicit="true"; shift
244
265
  ;;
245
266
  --claude)
246
267
  # No-op selector for symmetry with --codex / --opencode and install.sh's
247
268
  # --claude. Lets `./install.sh --uninstall --claude` (which forwards
248
269
  # remaining args here) succeed instead of hitting the unknown-flag
249
270
  # catch-all.
250
- target="claude"; shift
271
+ target="claude"; target_explicit="true"; shift
251
272
  ;;
252
273
  -h|--help)
253
274
  # awk avoids GNU `head -n -<N>` (rejected by BSD head on macOS).
@@ -260,7 +281,66 @@ while [ $# -gt 0 ]; do
260
281
  esac
261
282
  done
262
283
 
263
- 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
264
344
  err "jq is required for the $target uninstall path."
265
345
  exit 1
266
346
  fi
@@ -656,6 +736,7 @@ if [ "$target" = "opencode" ]; then
656
736
  refuse_if_symlink "$opencode_dir"
657
737
  fi
658
738
  opencode_config_file="$opencode_dir/opencode.json"
739
+ skip_if_not_installed "$opencode_config_file" '"weave(-claude|-codex)?"' "$opencode_dir/.weave-parked.json"
659
740
  opencode_parked="$opencode_dir/.weave-parked.json"
660
741
  opencode_direct_model=""
661
742
  refuse_if_symlink "$opencode_config_file"
@@ -785,6 +866,74 @@ EOF
785
866
  exit 0
786
867
  fi
787
868
 
869
+ # ---------- copilot uninstall path ----------
870
+
871
+ if [ "$target" = "copilot" ]; then
872
+ # Mirrors install.sh: user scope only; --dir is a throwaway COPILOT_HOME.
873
+ if [ -n "$install_dir" ]; then
874
+ install_dir="$(cd "$install_dir" 2>/dev/null && pwd || echo "$install_dir")"
875
+ copilot_dir="$install_dir/.copilot"
876
+ else
877
+ copilot_dir="${COPILOT_HOME:-$HOME/.copilot}"
878
+ fi
879
+ copilot_providers_file="$copilot_dir/providers.json"
880
+ copilot_settings_file="$copilot_dir/settings.json"
881
+ copilot_parked_file="$copilot_dir/.weave-parked.json"
882
+ for path in "$copilot_dir" "$copilot_providers_file" "$copilot_settings_file" "$copilot_parked_file"; do
883
+ refuse_if_symlink "$path"
884
+ done
885
+ skip_if_not_installed "$copilot_providers_file" '"name": *"weave"' "$copilot_parked_file"
886
+
887
+ if [ -f "$copilot_providers_file" ]; then
888
+ report_uninstall_event copilot \
889
+ "$(jq -r '[(.providers // [])[] | select(.name == "weave") | .baseUrl // empty][0] // empty' "$copilot_providers_file" 2>/dev/null | sed 's#/v1$##')" \
890
+ "$(jq -r '[(.providers // [])[] | select(.name == "weave") | .headers["X-Weave-Router-Key"] // empty][0] // empty' "$copilot_providers_file" 2>/dev/null)" || true
891
+ cleaned="$(jq '
892
+ .providers = [(.providers // [])[] | select(.name != "weave")]
893
+ | .models = [(.models // [])[] | select(.provider != "weave")]
894
+ ' "$copilot_providers_file")"
895
+ if [ "$(printf '%s' "$cleaned" | jq '(.providers | length) + (.models | length) + (del(.providers, .models) | length)')" = "0" ]; then
896
+ rm -f "$copilot_providers_file"
897
+ ok "Removed empty $copilot_providers_file"
898
+ else
899
+ printf '%s\n' "$cleaned" >"$copilot_providers_file"
900
+ chmod 600 "$copilot_providers_file"
901
+ ok "Removed the weave provider from $copilot_providers_file"
902
+ fi
903
+ else
904
+ info "No Copilot CLI providers.json at $copilot_providers_file (already uninstalled?)"
905
+ fi
906
+
907
+ if [ -f "$copilot_settings_file" ]; then
908
+ direct_model=""
909
+ [ -f "$copilot_parked_file" ] && direct_model="$(jq -r '.direct_model // empty' "$copilot_parked_file" 2>/dev/null || true)"
910
+ cleaned="$(jq --arg direct "$direct_model" '
911
+ if ((.model // "") | startswith("weave/"))
912
+ then (if $direct != "" then .model = $direct else del(.model) end)
913
+ else . end
914
+ ' "$copilot_settings_file")"
915
+ printf '%s\n' "$cleaned" >"$copilot_settings_file"
916
+ ok "Restored Copilot CLI default model in $copilot_settings_file${direct_model:+ ($direct_model)}"
917
+ fi
918
+ rm -f "$copilot_parked_file"
919
+
920
+ # Only remove skills that still carry our ownership marker.
921
+ if [ -d "$copilot_dir/skills" ] && [ ! -L "$copilot_dir/skills" ]; then
922
+ for skill_dir in "$copilot_dir"/skills/*/; do
923
+ [ -d "$skill_dir" ] || continue
924
+ skill_dir="${skill_dir%/}"
925
+ name="${skill_dir##*/}"
926
+ [ -L "$skill_dir" ] && continue
927
+ if [ ! -f "$skill_dir/SKILL.md" ] || [ -L "$skill_dir/SKILL.md" ]; then continue; fi
928
+ grep -Fq "<!-- weave-router managed $name skill -->" "$skill_dir/SKILL.md" || continue
929
+ rm -rf "$skill_dir"
930
+ done
931
+ rmdir "$copilot_dir/skills" 2>/dev/null || true
932
+ ok "Removed Weave Router Copilot skills"
933
+ fi
934
+ exit 0
935
+ fi
936
+
788
937
  # ---------- pi uninstall path ----------
789
938
 
790
939
  if [ "$target" = "pi" ]; then
@@ -836,6 +985,7 @@ if [ "$target" = "pi" ]; then
836
985
  refuse_if_symlink "$pi_settings_file"
837
986
  refuse_if_symlink "$pi_key_file"
838
987
 
988
+ skip_if_not_installed "$pi_models_file" '"weave"'
839
989
  report_pi_uninstall_event "$pi_models_file" "$pi_key_file" || true
840
990
  # models.json: drop provider.weave; remove the file if nothing else remains.
841
991
  # Other providers/models the user added are preserved.
@@ -953,6 +1103,7 @@ if [ "$target" = "codex" ]; then
953
1103
  # exits before strip_codex_block, so one symlinked helper left the config
954
1104
  # wired to a router the uninstall had just been asked to remove.
955
1105
 
1106
+ skip_if_not_installed "$codex_config_file" 'model_providers.weave'
956
1107
  report_codex_uninstall_event "$codex_config_file" || true
957
1108
  if [ -f "$codex_config_file" ]; then
958
1109
  strip_codex_block "$codex_config_file"
@@ -1146,6 +1297,8 @@ else
1146
1297
  refuse_if_symlink "$statusline_ownership_file"
1147
1298
  fi
1148
1299
 
1300
+ skip_if_not_installed "$settings_file" 'ANTHROPIC_BASE_URL|Weave Router|cc-statusline' \
1301
+ "$(dirname "$settings_file")/.weave-parked.json" "$(dirname "$settings_file")/.weave-context-window.json" "$statusline_file"
1149
1302
  statusline_file_owned="false"
1150
1303
  statusline_setting_owned="false"
1151
1304
  context_state_file="$(dirname "$settings_file")/.weave-context-window.json"
@@ -1175,6 +1328,7 @@ fi
1175
1328
 
1176
1329
  report_claude_uninstall_event || true
1177
1330
 
1331
+
1178
1332
  if [ -f "$settings_file" ]; then
1179
1333
  # Only remove keys we actually installed: scrub our env vars, and only
1180
1334
  # delete `statusLine` / `apiKeyHelper` when they point at scripts this
@@ -1186,6 +1340,11 @@ if [ -f "$settings_file" ]; then
1186
1340
  | (if (.env | length) == 0 then del(.env) else . end)
1187
1341
  else . end
1188
1342
  | (if $statusline_setting_owned == "true" then del(.statusLine) else . end)
1343
+ | (if (.hooks.UserPromptSubmit | type) == "array" then
1344
+ .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)))
1345
+ | (if (.hooks.UserPromptSubmit | length) == 0 then del(.hooks.UserPromptSubmit) else . end)
1346
+ | (if (.hooks | length) == 0 then del(.hooks) else . end)
1347
+ else . end)
1189
1348
  | (if (.apiKeyHelper // "" | tostring | endswith("weave-key.sh"))
1190
1349
  then del(.apiKeyHelper) else . end)
1191
1350
  | (if ((.attribution.commit == "Co-Authored-By: Weave Router <router@weaveos.com>"