@weave-os/router 0.2.22 → 0.2.24

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/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
 
@@ -676,14 +680,44 @@ strip_weave_codex_hooks() {
676
680
  rm -f "$tmp" 2>/dev/null || true
677
681
  }
678
682
 
683
+ # codex_existing_option finds a Codex setting before the managed block is
684
+ # replaced. Codex can save a selection inside our old block or immediately
685
+ # after it, where TOML incorrectly scopes it to the preceding table.
686
+ codex_existing_option() {
687
+ local config_file="$1" option="$2"
688
+ [ -f "$config_file" ] || return 0
689
+ awk -v begin="$WEAVE_CODEX_BEGIN_MARKER" -v end="$WEAVE_CODEX_END_MARKER" -v key="$option" '
690
+ BEGIN { option_pattern = "^[[:space:]]*" key "[[:space:]]*=" }
691
+ $0 == begin { in_managed = 1; managed_top = 1; after_managed = 0; next }
692
+ $0 == end { in_managed = 0; after_managed = 1; next }
693
+ /^[[:space:]]*\[/ {
694
+ in_section = 1
695
+ if (in_managed) managed_top = 0
696
+ else after_managed = 0
697
+ in_weave_provider = ($0 ~ /^[[:space:]]*\[[[:space:]]*model_providers[[:space:]]*\.[[:space:]]*weave[[:space:]]*\][[:space:]]*(#.*)?$/)
698
+ next
699
+ }
700
+ $0 ~ option_pattern {
701
+ if (!in_managed && !in_section) outside = $0
702
+ else if (!in_managed && (after_managed || in_weave_provider)) misplaced = $0
703
+ else if (in_managed && managed_top) managed = $0
704
+ }
705
+ END {
706
+ if (outside != "") print "T" outside
707
+ else if (misplaced != "") print "S" misplaced
708
+ else if (managed != "") print "B" managed
709
+ }
710
+ ' "$config_file"
711
+ }
712
+
679
713
  # write_codex_config writes a managed [model_providers.weave] block to the
680
714
  # Codex CLI's config.toml. Sets `model_provider = "weave"` at the top level so
681
715
  # Codex picks the routed provider by default. The provider requires OpenAI
682
716
  # authentication, preserving the user's ChatGPT plan credential while the
683
717
  # router key is sent independently. The router applies OAuth only to its
684
718
  # native gpt-5.6 Sol/Terra/Luna family; all other routed models use WorkWeave
685
- # deployment or BYOK credentials. Both settings live inside the managed-block
686
- # markers so uninstall removes them cleanly. We strip any
719
+ # deployment or BYOK credentials. The model choice stays outside the managed
720
+ # markers so Codex can update it without a reinstall resetting it. We strip any
687
721
  # top-level `model_provider = ...` declaration OUTSIDE the markers before
688
722
  # appending so the file doesn't end up with a duplicate key (TOML rejects
689
723
  # that). Inline `model_provider` keys inside `[profiles.*]` sections stay
@@ -697,6 +731,24 @@ write_codex_config() {
697
731
  local block_email="${4:-}"
698
732
  local block_name="${5:-}"
699
733
 
734
+ if [ "${WEAVE_CAPTURE_LLM_CLASSIFIER:-}" = "1" ]; then
735
+ local capture_url="${WEAVE_CAPTURE_PROXY_URL:-http://127.0.0.1:41984}"
736
+ if ! [[ "$capture_url" =~ ^http://(127\.0\.0\.1|localhost):[0-9]+$ ]]; then
737
+ err "Classifier opt-in requires a loopback WEAVE_CAPTURE_PROXY_URL"
738
+ return 1
739
+ fi
740
+ block_url="$capture_url"
741
+ if ! command -v jq >/dev/null 2>&1; then
742
+ err "Classifier opt-in requires jq to verify the capture proxy"
743
+ return 1
744
+ fi
745
+ if ! curl -fsS --max-time 2 "$capture_url/healthz" | jq -e --arg upstream "$2" \
746
+ '.classifier_enabled == true and .upstream == $upstream' >/dev/null; then
747
+ err "Classifier capture proxy is unavailable or targets a different router"
748
+ return 1
749
+ fi
750
+ fi
751
+
700
752
  # Escape `\` and `"` for TOML basic strings. Order matters: replace
701
753
  # backslashes first so the quotes we add next aren't double-escaped. A
702
754
  # display name like `John "J" Doe` would otherwise produce invalid TOML and
@@ -730,11 +782,21 @@ write_codex_config() {
730
782
  # Tag the client so telemetry can attribute traffic to Codex vs other CLIs
731
783
  # that share the same router key. The router otherwise has to guess from
732
784
  # User-Agent.
733
- headers_parts="${headers_parts}, \"X-App\" = \"codex\""
785
+ headers_parts="${headers_parts}, \"X-App\" = \"codex\", \"X-Weave-Codex-Native-Model-Pin\" = \"1\""
734
786
  # No strategy header: pinning one here freezes installed clients on whatever
735
787
  # policy was current at install time, so a deployment-default change never
736
788
  # reaches them. Every endpoint, hosted or self-hosted, uses its own default.
737
789
  local headers_line="http_headers = { ${headers_parts} }"
790
+ local codex_model_line='model = "weave-auto"' codex_effort_line="" saved_option
791
+ saved_option="$(codex_existing_option "$config_file" model)"
792
+ case "${saved_option:0:1}" in
793
+ T) codex_model_line="" ;;
794
+ S|B) codex_model_line="${saved_option:1}" ;;
795
+ esac
796
+ saved_option="$(codex_existing_option "$config_file" model_reasoning_effort)"
797
+ case "${saved_option:0:1}" in
798
+ S|B) codex_effort_line="${saved_option:1}" ;;
799
+ esac
738
800
 
739
801
  local hook_feature_line="features.hooks = true"
740
802
  local hook_block=""
@@ -753,6 +815,10 @@ write_codex_config() {
753
815
  if [ -f "$config_file" ] && grep -q '^\[features\]$' "$config_file"; then
754
816
  hook_feature_line=""
755
817
  fi
818
+ if [ "${WEAVE_CAPTURE_LLM_CLASSIFIER:-}" = "1" ] && [ "$codex_hooks_enabled" != "true" ]; then
819
+ err "Classifier opt-in requires managed Codex lifecycle hooks; existing hook configuration is incompatible"
820
+ return 1
821
+ fi
756
822
  if [ "$codex_hooks_enabled" = "true" ]; then
757
823
  # UserPromptSubmit is registered only when OUR hook is actually on disk.
758
824
  # Existence alone is the wrong test: install_codex_directive_script leaves
@@ -786,6 +852,22 @@ type = "command"
786
852
  command = "${esc_status}"
787
853
  TOML
788
854
  )${directive_hook_block}"
855
+ if [ "${WEAVE_CAPTURE_LLM_CLASSIFIER:-}" = "1" ]; then
856
+ hook_block="${hook_block}$(cat <<TOML
857
+
858
+ [[hooks.PreToolUse]]
859
+ matcher = "spawn_agent"
860
+ [[hooks.PreToolUse.hooks]]
861
+ type = "command"
862
+ command = "${esc_status}"
863
+
864
+ [[hooks.PreCompact]]
865
+ [[hooks.PreCompact.hooks]]
866
+ type = "command"
867
+ command = "${esc_status}"
868
+ TOML
869
+ )"
870
+ fi
789
871
  fi
790
872
  local block
791
873
  block="$(cat <<TOML
@@ -805,7 +887,10 @@ ${headers_line}
805
887
  ${hook_block}
806
888
  ${WEAVE_CODEX_END_MARKER}
807
889
  TOML
808
- )"
890
+ )"
891
+ local codex_insertion="$block"
892
+ [ -z "$codex_effort_line" ] || codex_insertion="${codex_effort_line}"$'\n'"${codex_insertion}"
893
+ [ -z "$codex_model_line" ] || codex_insertion="${codex_model_line}"$'\n'"${codex_insertion}"
809
894
 
810
895
  if [ -f "$config_file" ]; then
811
896
  local tmp; tmp="$(mktemp -t weave-codex.XXXXXX)"
@@ -825,10 +910,11 @@ TOML
825
910
  # refused to start with "duplicate key" while the installer reported
826
911
  # success.
827
912
  awk -v begin="$WEAVE_CODEX_BEGIN_MARKER" -v end="$WEAVE_CODEX_END_MARKER" '
828
- $0 == begin { skip = 1; next }
829
- $0 == end { skip = 0; next }
913
+ $0 == begin { skip = 1; after_managed = 0; next }
914
+ $0 == end { skip = 0; after_managed = 1; next }
830
915
  skip { next }
831
916
  /^[[:space:]]*\[/ {
917
+ after_managed = 0
832
918
  in_section = 1
833
919
  if ($0 ~ /^[[:space:]]*\[[[:space:]]*model_providers[[:space:]]*\.[[:space:]]*weave[[:space:]]*(\.[^]]*)?\][[:space:]]*(#.*)?$/) {
834
920
  in_weave_provider = 1
@@ -837,6 +923,9 @@ TOML
837
923
  in_weave_provider = 0
838
924
  }
839
925
  in_weave_provider { next }
926
+ after_managed && /^[[:space:]]*(model|model_reasoning_effort)[[:space:]]*=/ { next }
927
+ !in_section && /^[[:space:]]*#[[:space:]]*model_provider[[:space:]]*=[[:space:]]*"weave".*weave-router: off/ { next }
928
+ !in_section && /^[[:space:]]*#[[:space:]]*model[[:space:]]*=[[:space:]]*"weave-auto".*weave-router: off/ { next }
840
929
  !in_section && /^[[:space:]]*model_provider[[:space:]]*=/ { next }
841
930
  { print }
842
931
  ' "$config_file" >"$tmp"
@@ -872,7 +961,7 @@ EOF
872
961
  if [ "$first_section" -gt 1 ]; then
873
962
  head -n "$((first_section - 1))" "$tmp"
874
963
  fi
875
- printf "%s\n" "$block"
964
+ printf "%s\n" "$codex_insertion"
876
965
  tail -n "+${first_section}" "$tmp"
877
966
  } >"$config_file"
878
967
  else
@@ -880,11 +969,11 @@ EOF
880
969
  # already at top-level. Our block ends with its own [section], so
881
970
  # appending is safe (no bare keys follow).
882
971
  cp "$tmp" "$config_file"
883
- printf "\n%s\n" "$block" >>"$config_file"
972
+ printf "\n%s\n" "$codex_insertion" >>"$config_file"
884
973
  fi
885
974
  rm -f "$tmp"
886
975
  else
887
- printf "%s\n" "$block" >"$config_file"
976
+ printf "%s\n" "$codex_insertion" >"$config_file"
888
977
  fi
889
978
 
890
979
  # If the user already has a [features] table, place our managed hook
@@ -1021,19 +1110,20 @@ write_opencode_config() {
1021
1110
  # config; ChatGPT tokens live in opencode's own auth store), so 644 is fine.
1022
1111
  # Source is bundled alongside install.sh by the npm prepack
1023
1112
  # (scripts/copy-installer.js), same as commands/ + pi-router/.
1024
- local plugin_dir plugin_spec plugin_src plugin_arg=""
1113
+ local plugin_dir plugin_spec plugin_src plugin_directives_src plugin_classifier_src plugin_arg=""
1025
1114
  plugin_dir="$(cd "$(dirname "$config_file")" && pwd)/.weave"
1026
1115
  plugin_spec="$plugin_dir/opencode-weave.ts"
1027
1116
  plugin_src="$script_dir/opencode-weave/src/index.ts"
1028
1117
  plugin_directives_src="$script_dir/opencode-weave/src/directives.ts"
1029
- if [ -f "$plugin_src" ]; then
1118
+ plugin_classifier_src="$script_dir/opencode-weave/src/classifier-thread.ts"
1119
+ if [ -f "$plugin_src" ] && [ -f "$plugin_directives_src" ] && [ -f "$plugin_classifier_src" ]; then
1030
1120
  mkdir -p "$plugin_dir"
1031
1121
  cp "$plugin_src" "$plugin_spec"
1032
1122
  chmod 644 "$plugin_spec"
1033
- if [ -f "$plugin_directives_src" ]; then
1034
- cp "$plugin_directives_src" "$plugin_dir/directives.ts"
1035
- chmod 644 "$plugin_dir/directives.ts"
1036
- fi
1123
+ cp "$plugin_directives_src" "$plugin_dir/directives.ts"
1124
+ chmod 644 "$plugin_dir/directives.ts"
1125
+ cp "$plugin_classifier_src" "$plugin_dir/classifier-thread.ts"
1126
+ chmod 644 "$plugin_dir/classifier-thread.ts"
1037
1127
  plugin_arg="$plugin_spec"
1038
1128
  else
1039
1129
  warn "opencode subscription plugin source not found at $plugin_src — skipping the Claude login + subscription routing. (Use a packaged 'npx $npm_package_name' install.)"
@@ -1171,11 +1261,14 @@ write_pi_models_config() {
1171
1261
  models: [
1172
1262
  { id: "claude-fable-5-1", name: "Claude Fable 5.1 (via Weave Router)", reasoning: true, input: ["text","image"], contextWindow: 1000000, maxTokens: 128000 },
1173
1263
  { id: "claude-fable-5", name: "Claude Fable 5 (via Weave Router)", reasoning: true, input: ["text","image"], contextWindow: 1000000, maxTokens: 128000 },
1264
+ { id: "claude-opus-5-5", name: "Claude Opus 5.5 (via Weave Router)", reasoning: true, input: ["text","image"], contextWindow: 1000000, maxTokens: 128000 },
1174
1265
  { id: "claude-opus-5", name: "Claude Opus 5 (via Weave Router)", reasoning: true, input: ["text","image"], contextWindow: 1000000, maxTokens: 128000 },
1175
1266
  { id: "claude-opus-4-7", name: "Claude Opus 4.7 (via Weave Router)", reasoning: true, input: ["text","image"], contextWindow: 1000000, maxTokens: 64000 },
1176
1267
  { id: "claude-sonnet-4-6", name: "Claude Sonnet 4.6 (via Weave Router)", reasoning: true, input: ["text","image"], contextWindow: 1000000, maxTokens: 64000 },
1177
1268
  { id: "claude-haiku-4-5", name: "Claude Haiku 4.5 (via Weave Router)", reasoning: true, input: ["text","image"], contextWindow: 200000, maxTokens: 32000 },
1178
1269
  { id: "gpt-6-astra", name: "GPT-6 Astra (via Weave Router)", reasoning: true, input: ["text","image"], contextWindow: 1050000, maxTokens: 128000 },
1270
+ { id: "gpt-6-sol", name: "GPT-6 Sol (via Weave Router)", reasoning: true, input: ["text","image"], contextWindow: 1050000, maxTokens: 128000 },
1271
+ { id: "gpt-6-luna", name: "GPT-6 Luna (via Weave Router)", reasoning: true, input: ["text","image"], contextWindow: 1050000, maxTokens: 128000 },
1179
1272
  { id: "gpt-5.6-sol", name: "GPT-5.6 Sol (via Weave Router)", reasoning: true, input: ["text","image"], contextWindow: 1050000, maxTokens: 128000 },
1180
1273
  { id: "grok-4.5", name: "Grok 4.5 (via Weave Router)", reasoning: true, input: ["text","image"], contextWindow: 500000, maxTokens: 131072 },
1181
1274
  { id: "grok-4.6", name: "Grok 4.6 (via Weave Router)", reasoning: true, input: ["text","image"], contextWindow: 500000, maxTokens: 131072 },
@@ -1391,6 +1484,14 @@ while [ $# -gt 0 ]; do
1391
1484
  [ -n "$email" ] || { err "--email requires a value."; exit 2; }
1392
1485
  email_explicit="true"
1393
1486
  ;;
1487
+ --return-url)
1488
+ return_url="${2:-}"; shift 2
1489
+ [ -n "$return_url" ] || { err "--return-url requires a value."; exit 2; }
1490
+ case "$return_url" in
1491
+ http://*|https://*) ;;
1492
+ *) err "--return-url must be an http:// or https:// URL."; exit 2 ;;
1493
+ esac
1494
+ ;;
1394
1495
  --local)
1395
1496
  # Shorthand for local dev: localhost:8080 (matches `wv mr` / `make dev` default PORT).
1396
1497
  base_url="http://localhost:8080"
@@ -1504,6 +1605,11 @@ if [ "$mode" = "setup" ]; then
1504
1605
  [ "$non_interactive" = "true" ] && setup_args+=(--non-interactive)
1505
1606
  [ "$base_url_explicit" = "true" ] && setup_args+=(--base-url "$base_url")
1506
1607
  [ "$email_explicit" = "true" ] && setup_args+=(--email "$email")
1608
+ if [ -n "$return_url" ] && [ "$setup_claude" = "true" ] && [ "$setup_codex" = "true" ]; then
1609
+ err "--return-url with setup requires a single target: use setup --claude or setup --codex."
1610
+ exit 2
1611
+ fi
1612
+ [ -n "$return_url" ] && setup_args+=(--return-url "$return_url")
1507
1613
  [ -n "$install_dir" ] && setup_args+=(--dir "$install_dir")
1508
1614
  [ "$quiet" = "true" ] && setup_args+=(--quiet)
1509
1615
  [ "$rotate_key" = "true" ] && setup_args+=(--rotate-key)
@@ -1512,6 +1618,11 @@ if [ "$mode" = "setup" ]; then
1512
1618
  exit 0
1513
1619
  fi
1514
1620
 
1621
+ if [ -n "$return_url" ] && [ "$mode" != "install" ]; then
1622
+ err "--return-url is supported only for install (or setup with one explicit target)."
1623
+ exit 2
1624
+ fi
1625
+
1515
1626
  # --lsp is a pi-extension feature, so it implies the pi target; combining it
1516
1627
  # with another explicit target is a contradiction, not a preference.
1517
1628
  if [ -n "$lsp_langs" ]; then
@@ -2461,8 +2572,7 @@ prepare_claude_context_window() {
2461
2572
  if [ "$scope" = "project" ] && [ -z "$install_dir" ]; then
2462
2573
  context_settings_file="$local_settings_file"
2463
2574
  fi
2464
- context_state_file="$settings_dir/.weave-context-window.json"
2465
- refuse_if_symlink "$context_state_file"
2575
+ refuse_if_symlink "$settings_dir/.weave-context-window.json"
2466
2576
  [ -n "$context_window" ] || return 0
2467
2577
 
2468
2578
  local source model="" disabled="${CLAUDE_CODE_DISABLE_1M_CONTEXT:-}" env_model="${ANTHROPIC_MODEL:-}"
@@ -2484,7 +2594,7 @@ prepare_claude_context_window() {
2484
2594
  model="${model:-sonnet}"
2485
2595
  case "$model" in
2486
2596
  *'[1m]') context_window=""; return 0 ;;
2487
- sonnet|opus|fable|claude-sonnet-4-6|claude-sonnet-5|claude-opus-4-6|claude-opus-4-7|claude-opus-4-8|claude-opus-5|claude-fable-5|claude-fable-5-1) ;;
2597
+ sonnet|opus|fable|claude-sonnet-4-6|claude-sonnet-5|claude-opus-4-6|claude-opus-4-7|claude-opus-4-8|claude-opus-5|claude-opus-5-5|claude-fable-5|claude-fable-5-1) ;;
2488
2598
  *) err "Cannot assert 1M support for '$model'. Select a supported Sonnet/Opus/Fable model first; leaving it unchanged."; return 1 ;;
2489
2599
  esac
2490
2600
  context_managed_model="${model}[1m]"
@@ -2494,7 +2604,7 @@ apply_claude_context_window() {
2494
2604
  local action="$1" active="$2" state="$settings_dir/.weave-context-window.json" merged tmp
2495
2605
  refuse_if_symlink "$state"
2496
2606
  [ -f "$active" ] || return 0
2497
- if [ "$action" = "install" ] && [ -n "$context_window" ]; then
2607
+ if [ -n "$context_window" ]; then
2498
2608
  tmp="$(mktemp "$settings_dir/.weave-context.XXXXXX")"
2499
2609
  jq --arg managed "$context_managed_model" '{had_model: has("model"), original: .model, managed: $managed}' "$active" >"$tmp"
2500
2610
  chmod 600 "$tmp"
@@ -2502,13 +2612,13 @@ apply_claude_context_window() {
2502
2612
  merged="$(jq --arg model "$context_managed_model" '.model = $model' "$active")"
2503
2613
  else
2504
2614
  [ -f "$state" ] || return 0
2505
- merged="$(jq --slurpfile state "$state" --arg action "$action" '
2615
+ merged="$(jq --slurpfile state "$state" --arg action "$action" --arg context_window "$context_window" '
2506
2616
  $state[0] as $s |
2507
2617
  if $action == "off" then
2508
2618
  if .model == $s.managed then
2509
2619
  if $s.had_model then .model = $s.original else del(.model) end
2510
2620
  else . end
2511
- elif has("model") == $s.had_model and .model == $s.original then .model = $s.managed
2621
+ elif ($action == "install" or $action == "on") and has("model") == $s.had_model and .model == $s.original then .model = $s.managed
2512
2622
  else . end
2513
2623
  ' "$active")"
2514
2624
  fi
@@ -2516,7 +2626,7 @@ apply_claude_context_window() {
2516
2626
  printf '%s\n' "$merged" >"$tmp"
2517
2627
  chmod 600 "$tmp"
2518
2628
  mv "$tmp" "$active"
2519
- if [ "$action" = "install" ] && [ -n "$context_window" ]; then
2629
+ if [ -n "$context_window" ]; then
2520
2630
  ok "Claude Code model set to $context_managed_model; automatic compaction stays enabled. Restart Claude Code."
2521
2631
  if [ "$scope" = "project" ] && [ -z "$install_dir" ]; then
2522
2632
  gitignore_add ".claude/.weave-context-window.json"
@@ -2683,12 +2793,16 @@ toggle_claude() {
2683
2793
  toggle_codex() {
2684
2794
  local f="$codex_config_file" state="absent" tmp
2685
2795
  if [ -f "$f" ]; then
2686
- state="$(awk -v b="$WEAVE_CODEX_BEGIN_MARKER" -v e="$WEAVE_CODEX_END_MARKER" '
2687
- $0==b{inblk=1; next}
2688
- $0==e{inblk=0; next}
2689
- inblk && /^[[:space:]]*model_provider[[:space:]]*=[[:space:]]*"weave"/ {st="on"}
2690
- inblk && /^[[:space:]]*#[[:space:]]*model_provider[[:space:]]*=[[:space:]]*"weave"/ {if(st=="")st="off"}
2691
- END{print (st==""?"absent":st)}
2796
+ state="$(awk '
2797
+ /^[[:space:]]*\[[[:space:]]*model_providers[[:space:]]*\.[[:space:]]*weave[[:space:]]*\]/ { has_weave = 1 }
2798
+ /^[[:space:]]*\[/ { in_section = 1 }
2799
+ !in_section && /^[[:space:]]*model_provider[[:space:]]*=[[:space:]]*"weave"[[:space:]]*$/ { active_weave = 1 }
2800
+ !in_section && /^[[:space:]]*model_provider[[:space:]]*=/ { has_active_provider = 1 }
2801
+ END {
2802
+ if (!has_weave) print "absent"
2803
+ else if (active_weave) print "on"
2804
+ else print (has_active_provider ? "absent" : "off")
2805
+ }
2692
2806
  ' "$f")"
2693
2807
  fi
2694
2808
 
@@ -2704,10 +2818,12 @@ toggle_codex() {
2704
2818
  if [ "$state" = "absent" ]; then info "Codex isn't configured for the router. Run the installer first."; return 0; fi
2705
2819
  if [ "$state" = "off" ]; then ok "Codex is already off — nothing to do."; return 0; fi
2706
2820
  tmp="$(mktemp -t weave-codex-toggle.XXXXXX)"
2707
- awk -v b="$WEAVE_CODEX_BEGIN_MARKER" -v e="$WEAVE_CODEX_END_MARKER" '
2708
- $0==b{inblk=1; print; next}
2709
- $0==e{inblk=0; print; next}
2710
- inblk && /^[[:space:]]*model_provider[[:space:]]*=[[:space:]]*"weave"[[:space:]]*$/ {
2821
+ awk '
2822
+ /^[[:space:]]*\[/ { in_section = 1 }
2823
+ !in_section && /^[[:space:]]*model_provider[[:space:]]*=[[:space:]]*"weave"[[:space:]]*$/ {
2824
+ print "# " $0 " # weave-router: off (run on to re-enable)"; next
2825
+ }
2826
+ !in_section && /^[[:space:]]*model[[:space:]]*=[[:space:]]*"weave-auto"[[:space:]]*$/ {
2711
2827
  print "# " $0 " # weave-router: off (run on to re-enable)"; next
2712
2828
  }
2713
2829
  {print}
@@ -2722,13 +2838,39 @@ toggle_codex() {
2722
2838
  if [ "$state" = "absent" ]; then warn "No managed Weave block in $f. Run the installer to set up Codex."; return 0; fi
2723
2839
  if [ "$state" = "on" ]; then ok "Codex is already on — nothing to do."; return 0; fi
2724
2840
  tmp="$(mktemp -t weave-codex-toggle.XXXXXX)"
2725
- awk -v b="$WEAVE_CODEX_BEGIN_MARKER" -v e="$WEAVE_CODEX_END_MARKER" '
2726
- $0==b{inblk=1; print; next}
2727
- $0==e{inblk=0; print; next}
2728
- inblk && /^[[:space:]]*#[[:space:]]*model_provider[[:space:]]*=[[:space:]]*"weave"/ {
2729
- print "model_provider = \"weave\""; next
2841
+ local has_top_model="false"
2842
+ if awk '
2843
+ /^[[:space:]]*\[/ { in_section = 1 }
2844
+ !in_section && /^[[:space:]]*model[[:space:]]*=/ { found = 1 }
2845
+ END { exit(found ? 0 : 1) }
2846
+ ' "$f"; then
2847
+ has_top_model="true"
2848
+ fi
2849
+ awk -v has_top_model="$has_top_model" '
2850
+ function add_missing_settings() {
2851
+ if (!restored_provider) print "model_provider = \"weave\""
2852
+ if (has_top_model != "true" && !restored_model) print "model = \"weave-auto\""
2853
+ }
2854
+ /^[[:space:]]*\[/ {
2855
+ if (!in_section) add_missing_settings()
2856
+ in_section = 1
2857
+ }
2858
+ !in_section && /^[[:space:]]*#[[:space:]]*model_provider[[:space:]]*=[[:space:]]*"weave".*weave-router: off/ {
2859
+ if (!restored_provider) {
2860
+ print "model_provider = \"weave\""
2861
+ restored_provider = 1
2862
+ }
2863
+ next
2864
+ }
2865
+ !in_section && /^[[:space:]]*#[[:space:]]*model[[:space:]]*=[[:space:]]*"weave-auto".*weave-router: off/ {
2866
+ if (has_top_model != "true" && !restored_model) {
2867
+ print "model = \"weave-auto\""
2868
+ restored_model = 1
2869
+ }
2870
+ next
2730
2871
  }
2731
2872
  {print}
2873
+ END { if (!in_section) add_missing_settings() }
2732
2874
  ' "$f" >"$tmp" && mv "$tmp" "$f"
2733
2875
  chmod 600 "$f"
2734
2876
  if [ -f "$codex_status_file" ] && grep -Fq '<!-- weave-router managed codex status -->' "$codex_status_file"; then
@@ -3185,6 +3327,47 @@ oauth_base64url() {
3185
3327
  openssl base64 -A | tr '+/' '-_' | tr -d '='
3186
3328
  }
3187
3329
 
3330
+ # open_url_in_browser asks the operating system to open a URL with the user's
3331
+ # default browser. Keep this best-effort: a successful install must not be
3332
+ # rolled back just because a headless shell has no browser opener available.
3333
+ open_url_in_browser() {
3334
+ local url="$1" os
3335
+ os="$(uname -s 2>/dev/null || printf '')"
3336
+ case "$os" in
3337
+ Darwin*)
3338
+ command -v open >/dev/null 2>&1 || return 1
3339
+ open "$url" >/dev/null 2>&1
3340
+ ;;
3341
+ MINGW*|MSYS*|CYGWIN*)
3342
+ # explorer.exe is a direct process launch; cmd.exe /c start would parse
3343
+ # URL query separators such as '&' as shell syntax. Its exit status is
3344
+ # not meaningful: an already-running shell commonly returns 1 after
3345
+ # handing the URL off.
3346
+ command -v explorer.exe >/dev/null 2>&1 || return 1
3347
+ explorer.exe "$url" >/dev/null 2>&1 || true
3348
+ return 0
3349
+ ;;
3350
+ *)
3351
+ command -v xdg-open >/dev/null 2>&1 || return 1
3352
+ xdg-open "$url" >/dev/null 2>&1
3353
+ ;;
3354
+ esac
3355
+ }
3356
+
3357
+ open_return_url_if_verified() {
3358
+ [ "$mode" = "install" ] || return 0
3359
+ [ -n "$return_url" ] || return 0
3360
+ if [ "${install_verification_succeeded:-false}" != "true" ]; then
3361
+ warn "Skipping return URL because router verification did not complete successfully."
3362
+ return 0
3363
+ fi
3364
+ if open_url_in_browser "$return_url"; then
3365
+ info "Opened return URL in your browser: $return_url"
3366
+ else
3367
+ warn "Install succeeded, but no default-browser opener was available. Open this URL to continue: $return_url"
3368
+ fi
3369
+ }
3370
+
3188
3371
  open_oauth_url() {
3189
3372
  local url="$1"
3190
3373
  if command -v open >/dev/null 2>&1; then
@@ -3910,15 +4093,25 @@ rewrite_installed_key() {
3910
4093
  }
3911
4094
 
3912
4095
  verify_install() {
3913
- if [ "$quiet" != "true" ]; then
3914
- if ! spin "Pinging $base_url/health" curl -fsS --max-time 5 "$base_url/health"; then
4096
+ local health_verified="false"
4097
+ install_verification_succeeded="false"
4098
+
4099
+ # --quiet normally skips the health probe, but a return URL is only safe to
4100
+ # open after both probes have actually run and passed.
4101
+ if [ "$quiet" != "true" ] || [ -n "$return_url" ]; then
4102
+ if spin "Pinging $base_url/health" curl -fsS --max-time 5 "$base_url/health"; then
4103
+ health_verified="true"
4104
+ else
3915
4105
  warn "Could not reach $base_url/health within 5s. Settings are written; verify the router is running."
3916
4106
  fi
3917
4107
  fi
3918
4108
 
3919
4109
  [ -n "$api_key" ] || return 0
3920
4110
 
3921
- spin "Validating API key" validate_key && return 0
4111
+ if spin "Validating API key" validate_key; then
4112
+ [ "$health_verified" = "true" ] && install_verification_succeeded="true"
4113
+ return 0
4114
+ fi
3922
4115
 
3923
4116
  # A key we read back off disk can have been revoked or rotated since it was
3924
4117
  # installed, and reusing it silently would leave a broken install behind
@@ -3931,7 +4124,9 @@ verify_install() {
3931
4124
  warn "The router key already installed was rejected (revoked or rotated)."
3932
4125
  prompt_for_key
3933
4126
  rewrite_installed_key "$api_key"
3934
- if ! spin "Validating API key" validate_key; then
4127
+ if spin "Validating API key" validate_key; then
4128
+ [ "$health_verified" = "true" ] && install_verification_succeeded="true"
4129
+ else
3935
4130
  warn "Router rejected the API key (check it matches the dashboard at $base_url)."
3936
4131
  fi
3937
4132
  return 0
@@ -3966,6 +4161,7 @@ announce_done() {
3966
4161
  fi
3967
4162
  printf "%s✓%s %s%sWeave Router installed for %s.%s\n" \
3968
4163
  "$C_GREEN" "$C_RESET" "$C_BOLD" "$C_BRAND" "$1" "$C_RESET"
4164
+ open_return_url_if_verified
3969
4165
  }
3970
4166
 
3971
4167
  # ---------- codex install path (dispatch + exit before the Claude-only writes) ----------
@@ -4057,6 +4253,9 @@ set -euo pipefail
4057
4253
  # WEAVE_STATUSLINE_UPDATE and WEAVE_STATUSLINE_UPDATE_INTERVAL_DAYS variables
4058
4254
  # remain accepted as aliases for users who configure both clients together.
4059
4255
  weave_self_refresh() {
4256
+ # The published helper may predate classifier lifecycle forwarding. Do not
4257
+ # replace the hook implementation underneath an opted-in session.
4258
+ [ "${WEAVE_CAPTURE_LLM_CLASSIFIER:-}" = "1" ] && return 0
4060
4259
  [ "${WEAVE_CODEX_STATUS_UPDATE:-${WEAVE_STATUSLINE_UPDATE:-1}}" = "0" ] && return 0
4061
4260
  command -v curl >/dev/null 2>&1 || return 0
4062
4261
 
@@ -4123,9 +4322,10 @@ emit_title() {
4123
4322
  local title="$1"
4124
4323
  if [ -n "${WEAVE_CODEX_STATUS_TITLE_FILE:-}" ]; then
4125
4324
  printf '%s\n' "$title" >"$WEAVE_CODEX_STATUS_TITLE_FILE"
4126
- elif [ -w /dev/tty ]; then
4325
+ elif [ -t 2 ] && [ -w /dev/tty ]; then
4127
4326
  printf '\033]0;%s\007' "$title" >/dev/tty
4128
4327
  fi
4328
+ return 0
4129
4329
  }
4130
4330
 
4131
4331
  safe_session_id() {
@@ -4353,6 +4553,21 @@ command -v jq >/dev/null 2>&1 || exit 0
4353
4553
  jq -e . >/dev/null 2>&1 <<<"$payload" || exit 0
4354
4554
 
4355
4555
  hook_event_name="$(jq -r '.hook_event_name // ""' <<<"$payload")"
4556
+ if [ "${WEAVE_CAPTURE_LLM_CLASSIFIER:-}" = "1" ] && [ -n "${WEAVE_CAPTURE_HOOK_TOKEN:-}" ]; then
4557
+ classifier_hook_url="${WEAVE_CAPTURE_HOOK_URL:-http://127.0.0.1:41984/classifier/hook}"
4558
+ if [[ "$classifier_hook_url" =~ ^http://(127\.0\.0\.1|localhost|\[::1\]):[0-9]+/classifier/hook$ ]]; then
4559
+ case "$hook_event_name" in
4560
+ SessionStart|PreToolUse|PreCompact)
4561
+ # Send lifecycle identifiers only. A failed hook cannot enroll a thread;
4562
+ # the opted-in capture proxy rejects its inference request instead.
4563
+ jq -c '{hook_event_name,session_id,source,tool_name}' <<<"$payload" |
4564
+ curl -fsS --max-time 2 -H 'Content-Type: application/json' \
4565
+ -H "X-Weave-Capture-Hook-Token: $WEAVE_CAPTURE_HOOK_TOKEN" \
4566
+ --data-binary @- "$classifier_hook_url" >/dev/null 2>&1 || true
4567
+ ;;
4568
+ esac
4569
+ fi
4570
+ fi
4356
4571
  if [ "$hook_event_name" = "SessionStart" ]; then
4357
4572
  if [ -f "$disabled_marker" ]; then
4358
4573
  emit_title "Codex · direct"
@@ -4362,6 +4577,10 @@ if [ "$hook_event_name" = "SessionStart" ]; then
4362
4577
  exit 0
4363
4578
  fi
4364
4579
 
4580
+ if [ "$hook_event_name" = "PreToolUse" ] || [ "$hook_event_name" = "PreCompact" ]; then
4581
+ exit 0
4582
+ fi
4583
+
4365
4584
  if [ -f "$disabled_marker" ]; then
4366
4585
  exit 0
4367
4586
  fi
@@ -4782,8 +5001,7 @@ if [ "$target" = "opencode" ]; then
4782
5001
  for entry in \
4783
5002
  "opencode.json" \
4784
5003
  ".weave/" \
4785
- ".weave-parked.json" \
4786
- ".opencode/commands/*.weave-router"
5004
+ ".weave-parked.json"
4787
5005
  do
4788
5006
  if [ ! -f "$gitignore" ] || ! grep -qxF "$entry" "$gitignore"; then
4789
5007
  printf '%s\n' "$entry" >>"$gitignore"
@@ -5368,12 +5586,14 @@ prices='{
5368
5586
  "claude-opus-4-7": 0.005,
5369
5587
  "claude-opus-4-8": 0.005,
5370
5588
  "claude-opus-5": 0.005,
5589
+ "claude-opus-5-5": 0.004,
5371
5590
  "claude-sonnet-4-5": 0.003,
5372
5591
  "claude-sonnet-4-6": 0.003,
5373
5592
  "claude-sonnet-5": 0.003,
5374
5593
  "deepseek/deepseek-v4-flash": 0.0001134,
5375
5594
  "deepseek/deepseek-v4-pro": 0.00174,
5376
5595
  "deepseek/deepseek-v4-pro-0813": 0.00174,
5596
+ "deepseek/deepseek-v4.1-flash": 0.00022,
5377
5597
  "gemini-2.0-flash": 0.0001,
5378
5598
  "gemini-2.0-flash-lite": 0.000075,
5379
5599
  "gemini-2.5-flash": 0.0003,
@@ -5412,9 +5632,12 @@ prices='{
5412
5632
  "gpt-5.6-sol-pro": 0.004,
5413
5633
  "gpt-5.6-terra": 0.002,
5414
5634
  "gpt-6-astra": 0.01,
5635
+ "gpt-6-luna": 0.0001,
5636
+ "gpt-6-sol": 0.002,
5415
5637
  "grok-4.5": 0.002,
5416
5638
  "grok-4.6": 0.002,
5417
5639
  "grok-4.7": 0.002,
5640
+ "inclusionai/ling-3.0-flash": 0.00006,
5418
5641
  "minimax/minimax-m2.7": 0.0003,
5419
5642
  "minimax/minimax-m3": 0.0003,
5420
5643
  "mistralai/mistral-small-2603": 0.0002,
@@ -5433,6 +5656,8 @@ prices='{
5433
5656
  "qwen/qwen3.7-plus": 0.0004,
5434
5657
  "qwen/qwen3.8-max": 0.002,
5435
5658
  "xiaomi/mimo-v2.5-pro": 0.001,
5659
+ "xiaomi/mimo-v2.6-flash": 0.00014,
5660
+ "xiaomi/mimo-v2.6-pro": 0.000435,
5436
5661
  "z-ai/glm-5": 0.001,
5437
5662
  "z-ai/glm-5.1": 0.0014,
5438
5663
  "z-ai/glm-5.2": 0.0014,
@@ -5450,12 +5675,14 @@ prices='{
5450
5675
  "claude-opus-4-7": 0.025,
5451
5676
  "claude-opus-4-8": 0.025,
5452
5677
  "claude-opus-5": 0.025,
5678
+ "claude-opus-5-5": 0.02,
5453
5679
  "claude-sonnet-4-5": 0.015,
5454
5680
  "claude-sonnet-4-6": 0.015,
5455
5681
  "claude-sonnet-5": 0.015,
5456
5682
  "deepseek/deepseek-v4-flash": 0.0002791,
5457
5683
  "deepseek/deepseek-v4-pro": 0.00348,
5458
5684
  "deepseek/deepseek-v4-pro-0813": 0.00348,
5685
+ "deepseek/deepseek-v4.1-flash": 0.00066,
5459
5686
  "gemini-2.0-flash": 0.0004,
5460
5687
  "gemini-2.0-flash-lite": 0.0003,
5461
5688
  "gemini-2.5-flash": 0.0012,
@@ -5494,9 +5721,12 @@ prices='{
5494
5721
  "gpt-5.6-sol-pro": 0.02,
5495
5722
  "gpt-5.6-terra": 0.012,
5496
5723
  "gpt-6-astra": 0.05,
5724
+ "gpt-6-luna": 0.0005,
5725
+ "gpt-6-sol": 0.01,
5497
5726
  "grok-4.5": 0.006,
5498
5727
  "grok-4.6": 0.006,
5499
5728
  "grok-4.7": 0.006,
5729
+ "inclusionai/ling-3.0-flash": 0.00018,
5500
5730
  "minimax/minimax-m2.7": 0.0012,
5501
5731
  "minimax/minimax-m3": 0.0012,
5502
5732
  "mistralai/mistral-small-2603": 0.0006,
@@ -5515,6 +5745,8 @@ prices='{
5515
5745
  "qwen/qwen3.7-plus": 0.0016,
5516
5746
  "qwen/qwen3.8-max": 0.006,
5517
5747
  "xiaomi/mimo-v2.5-pro": 0.003,
5748
+ "xiaomi/mimo-v2.6-flash": 0.00028,
5749
+ "xiaomi/mimo-v2.6-pro": 0.00087,
5518
5750
  "z-ai/glm-5": 0.0032,
5519
5751
  "z-ai/glm-5.1": 0.0044,
5520
5752
  "z-ai/glm-5.2": 0.0044,
@@ -5532,12 +5764,14 @@ prices='{
5532
5764
  "claude-opus-4-7": 0.1,
5533
5765
  "claude-opus-4-8": 0.1,
5534
5766
  "claude-opus-5": 0.1,
5767
+ "claude-opus-5-5": 0.05,
5535
5768
  "claude-sonnet-4-5": 0.1,
5536
5769
  "claude-sonnet-4-6": 0.1,
5537
5770
  "claude-sonnet-5": 0.1,
5538
5771
  "deepseek/deepseek-v4-flash": 0.2,
5539
5772
  "deepseek/deepseek-v4-pro": 0.11494252873563218,
5540
5773
  "deepseek/deepseek-v4-pro-0813": 0.11494252873563218,
5774
+ "deepseek/deepseek-v4.1-flash": 0.031818181818181815,
5541
5775
  "gemini-2.0-flash": 0.25,
5542
5776
  "gemini-2.0-flash-lite": 0.25,
5543
5777
  "gemini-2.5-flash": 0.1,
@@ -5576,9 +5810,12 @@ prices='{
5576
5810
  "gpt-5.6-sol-pro": 0.1,
5577
5811
  "gpt-5.6-terra": 0.1,
5578
5812
  "gpt-6-astra": 0.1,
5813
+ "gpt-6-luna": 0.1,
5814
+ "gpt-6-sol": 0.1,
5579
5815
  "grok-4.5": 0.25,
5580
5816
  "grok-4.6": 0.25,
5581
5817
  "grok-4.7": 0.25,
5818
+ "inclusionai/ling-3.0-flash": 0.2,
5582
5819
  "minimax/minimax-m2.7": 0.2,
5583
5820
  "minimax/minimax-m3": 0.2,
5584
5821
  "mistralai/mistral-small-2603": 0.1,
@@ -5597,6 +5834,8 @@ prices='{
5597
5834
  "qwen/qwen3.7-plus": 0.2,
5598
5835
  "qwen/qwen3.8-max": 0.125,
5599
5836
  "xiaomi/mimo-v2.5-pro": 0.1,
5837
+ "xiaomi/mimo-v2.6-flash": 0.02,
5838
+ "xiaomi/mimo-v2.6-pro": 0.00827586,
5600
5839
  "z-ai/glm-5": 0.2,
5601
5840
  "z-ai/glm-5.1": 0.18571428571428572,
5602
5841
  "z-ai/glm-5.2": 0.18571428571428572,
@@ -5964,7 +6203,11 @@ write_claude_settings() {
5964
6203
  chmod 600 "$local_settings_file"
5965
6204
  ok "Router key header written to $local_settings_file"
5966
6205
  fi
5967
- apply_claude_context_window install "$context_settings_file"
6206
+ context_window_action="install"
6207
+ if [ "$mode" = "update" ] && [ ! -f "$settings_dir/.weave-parked.json" ]; then
6208
+ context_window_action="update"
6209
+ fi
6210
+ apply_claude_context_window "$context_window_action" "$context_settings_file"
5968
6211
  }
5969
6212
 
5970
6213
  # write_claude_settings rewrites the full router config live, so a parked
@@ -5997,8 +6240,7 @@ if [ "$scope" = "project" ] && [ -z "$install_dir" ] && [ -n "${git_root:-}" ];
5997
6240
  ".claude/settings.local.json" \
5998
6241
  ".claude/.credentials.json" \
5999
6242
  ".claude/cc-statusline.sh" \
6000
- ".claude/cc-statusline.sh.weave-router" \
6001
- ".claude/commands/*.weave-router"
6243
+ ".claude/cc-statusline.sh.weave-router"
6002
6244
  do
6003
6245
  [[ "$entry" == .claude/cc-statusline.sh* ]] && [ "$statusline_install" != "true" ] && continue
6004
6246
  if [ ! -f "$gitignore" ] || ! grep -qxF "$entry" "$gitignore"; then