@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 CHANGED
@@ -104,9 +104,11 @@ Four install targets:
104
104
  block plus `model_provider = "weave"`. Fresh installs select `weave-auto`,
105
105
  while reinstalling preserves an existing model choice. The provider preserves
106
106
  the active ChatGPT OAuth login. No install pins `X-Weave-Router-Strategy`;
107
- every endpoint keeps its router's configured default. Codex's native
108
- `/model` picker can force a named model and its selected reasoning effort;
109
- **Weave Router (automatic)** resumes per-request routing. An existing `$fm`
107
+ every endpoint keeps its router's configured default. Switching models with
108
+ Codex's native `/model` picker mid-session forces the named model and its
109
+ selected reasoning effort; the model a session launches with stays a
110
+ baseline that routes automatically, and selecting **Weave Router** resumes
111
+ per-request routing. An existing `$fm`
110
112
  session pin still applies in automatic mode until `$ufm` clears it. Re-run
111
113
  `npx @weave-os/router --codex` and restart Codex to enable this on an older
112
114
  install. `gpt-5.6-sol`, `gpt-5.6-terra`, `gpt-5.6-luna`, and `gpt-6-sol`
@@ -129,9 +131,11 @@ Four install targets:
129
131
  `~/.config/opencode/opencode.json` (or `<repo>/opencode.json` with
130
132
  `--scope project`). Installation activates `weave/auto` and parks any prior
131
133
  default model so `off` and uninstall can restore it exactly. The bundled
132
- plugin can attach ChatGPT and Claude plan credentials to the matching routed
133
- turns. Re-install rewrites only the managed provider; unrelated providers,
134
- MCP servers, agents, and plugins stay untouched.
134
+ plugin supplies OpenCode lifecycle, classifier, and directive hooks; managed
135
+ subscription enrollment is handled by `npx @weave-os/router login claude`
136
+ or `login codex`, not request headers. Re-install rewrites only the managed
137
+ provider and plugin entry; unrelated providers, MCP servers, agents, and
138
+ plugins stay untouched.
135
139
  - **pi** (`--pi`) — registers the `weave` provider and installs this package as
136
140
  a pi extension. Stock pi then gets the Loom startup header, Wooly's animated
137
141
  mascot, the persistent actual-route display, cumulative session savings,
package/install.sh CHANGED
@@ -131,8 +131,7 @@ router_key_header="X-Weave-Router-Key"
131
131
  # provider block into opencode.json. Each target carries its own
132
132
  # credential-passthrough story in the router: Claude Code's logged-in
133
133
  # Anthropic key flows through unchanged, Codex's ChatGPT credential flows
134
- # through its native provider, and opencode uses the Responses API plus
135
- # dedicated subscription headers. target_explicit tracks whether
134
+ # through its native provider, and opencode uses the Responses API. target_explicit tracks whether
136
135
  # --claude / --codex / --opencode was passed so an interactive run can
137
136
  # prompt for the choice.
138
137
  target="claude"
@@ -999,26 +998,16 @@ EOF
999
998
  chmod 600 "$config_file"
1000
999
  }
1001
1000
 
1002
- # write_opencode_config merges the managed Weave provider(s) into opencode's
1003
- # opencode.json plus the bundled subscription plugin:
1001
+ # write_opencode_config merges the managed Weave provider into opencode's
1002
+ # opencode.json and registers the bundled routing hooks. Subscription
1003
+ # enrollment is handled by the router's login command, so opencode only needs
1004
+ # this provider and its router key:
1004
1005
  # - provider.weave : OpenAI/Responses-shaped (@ai-sdk/openai → /v1/responses).
1005
1006
  # The single request provider. The router routes every
1006
- # turn across all models the caller's subscriptions +
1007
- # Weave key can pay for, and bills the plan matching the
1008
- # model it served. The default.
1009
- # - provider.weave-claude : login-only storage for a Claude (Pro/Max) subscription
1010
- # (no models, never serves requests). Written only when
1011
- # the bundled plugin is present, since the Claude login
1012
- # method lives in the plugin. The `weave` loader reads
1013
- # this slot and attaches the Claude sub.
1014
- # The plugin (src bundled at $script_dir/opencode-weave/src/index.ts) is dropped
1015
- # into $opencode_dir/.weave/ and registered via opencode.json's `plugin` array
1016
- # by absolute path — scope-independent (no reliance on an auto-load dir). It owns
1017
- # both the ChatGPT (on `weave`) and Claude (on `weave-claude`) logins and attaches
1018
- # whichever subscriptions are connected to every request via the router's
1019
- # dedicated X-Weave-*-Subscription headers. Re-running rewrites the blocks
1020
- # in-place via jq (and strips the legacy `weave-codex` provider); uninstall
1021
- # strips them.
1007
+ # turn across the models the router can serve. The default.
1008
+ # Re-running rewrites the block in-place via jq and strips the legacy
1009
+ # `weave-codex` provider. The plugin is retained for lifecycle/classifier and
1010
+ # directive hooks, but has no login or subscription-header transport.
1022
1011
  #
1023
1012
  # Usage: write_opencode_config <config_file_path> <base_url> <api_key> [user_email] [user_name]
1024
1013
  write_opencode_config() {
@@ -1029,10 +1018,8 @@ write_opencode_config() {
1029
1018
  local block_name="${5:-}"
1030
1019
 
1031
1020
  # Build the headers object piecewise so empty email/name vanish from the
1032
- # final JSON. opencode forwards the `headers` map verbatim to the upstream
1033
- # provider, so the router sees the same X-Weave-* triplet here that it
1034
- # would from Claude Code or Codex. The X-App tag lets router telemetry
1035
- # attribute traffic to opencode specifically.
1021
+ # final JSON. The X-App tag lets router telemetry attribute traffic to
1022
+ # opencode specifically.
1036
1023
  local headers_json
1037
1024
  headers_json="$(jq -n \
1038
1025
  --arg key "$block_key" \
@@ -1056,9 +1043,7 @@ write_opencode_config() {
1056
1043
  # /v1/responses surface (the canonical inbound — the router translates to
1057
1044
  # Anthropic/OSS as it routes, and ships verbatim to the Codex backend for GPT
1058
1045
  # turns). apiKey is the router key as a parse-time placeholder; the router
1059
- # authenticates off X-Weave-Router-Key (planted in headers) and the plugin's
1060
- # loader attaches subscriptions via the dedicated X-Weave-*-Subscription
1061
- # headers, so the apiKey value is never used upstream.
1046
+ # authenticates off X-Weave-Router-Key (planted in headers).
1062
1047
  local block
1063
1048
  block="$(jq -n \
1064
1049
  --arg url "$block_url/v1" \
@@ -1066,7 +1051,7 @@ write_opencode_config() {
1066
1051
  --argjson headers "$headers_json" '
1067
1052
  {
1068
1053
  npm: "@ai-sdk/openai",
1069
- name: "Weave Router — Codex plan",
1054
+ name: "Weave Router",
1070
1055
  options: { apiKey: $key, baseURL: $url, headers: $headers },
1071
1056
  models: {
1072
1057
  auto: {
@@ -1080,36 +1065,10 @@ write_opencode_config() {
1080
1065
  }
1081
1066
  ')"
1082
1067
 
1083
- # Login-only storage provider for a Claude (Pro/Max) subscription. It serves
1084
- # no requests (no models), so its npm/baseURL are inert — opencode just needs
1085
- # it registered so the plugin's Claude login method has a home and `opencode
1086
- # auth login` lists it. The `weave` loader reads this slot off disk and
1087
- # attaches the Claude sub. Reuses the same router key + identity headers.
1088
- local claude_block
1089
- claude_block="$(jq -n \
1090
- --arg url "$block_url/v1" \
1091
- --arg key "$block_key" \
1092
- --argjson headers "$headers_json" '
1093
- {
1094
- npm: "@ai-sdk/openai",
1095
- name: "Weave Router — Claude plan",
1096
- options: { apiKey: $key, baseURL: $url, headers: $headers },
1097
- models: {}
1098
- }
1099
- ')"
1100
-
1101
- # Drop the Codex-subscription plugin next to the config and capture the
1102
- # absolute path we'll register in opencode.json's `plugin` array (so it loads
1103
- # regardless of scope). $config_file's dir is the already-created
1104
- # opencode_dir, so the `cd … && pwd` canonicalization is safe — uninstall.sh
1105
- # must canonicalize identically so the array entry matches on removal.
1106
- #
1107
- # Only register the path when the bundled source is actually present and
1108
- # copied: registering a path with no file on disk makes opencode fail to load
1109
- # a missing plugin. The plugin holds no secrets (router key lives in the
1110
- # config; ChatGPT tokens live in opencode's own auth store), so 644 is fine.
1111
- # Source is bundled alongside install.sh by the npm prepack
1112
- # (scripts/copy-installer.js), same as commands/ + pi-router/.
1068
+ # Drop the routing plugin next to the config and register its absolute path
1069
+ # so it loads regardless of OpenCode scope. It contains lifecycle,
1070
+ # classifier, and directive hooks; managed subscription enrollment lives in
1071
+ # the router's login command and is never transported in request headers.
1113
1072
  local plugin_dir plugin_spec plugin_src plugin_directives_src plugin_classifier_src plugin_arg=""
1114
1073
  plugin_dir="$(cd "$(dirname "$config_file")" && pwd)/.weave"
1115
1074
  plugin_spec="$plugin_dir/opencode-weave.ts"
@@ -1126,7 +1085,7 @@ write_opencode_config() {
1126
1085
  chmod 644 "$plugin_dir/classifier-thread.ts"
1127
1086
  plugin_arg="$plugin_spec"
1128
1087
  else
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.)"
1088
+ warn "opencode routing plugin source not found at $plugin_src — skipping lifecycle and classifier hooks. (Use a packaged 'npx $npm_package_name' install.)"
1130
1089
  fi
1131
1090
 
1132
1091
  # Installing must actually activate the router. Preserve a prior direct model
@@ -1153,46 +1112,39 @@ write_opencode_config() {
1153
1112
  # file (other providers, mcp, agent settings) untouched. The managed model is
1154
1113
  # always weave/auto; a prior direct choice was parked above for exact restore.
1155
1114
  #
1156
- # The weave-claude login provider AND the plugin entry are written together
1157
- # only when the bundled plugin was present and copied ($plugin non-empty): the
1158
- # Claude login method lives in the plugin, so registering the provider without
1159
- # it (e.g. the `curl | sh` path, which carries no plugin source) would leave a
1160
- # non-working login — instead we omit it (and strip any stale one). The legacy
1161
- # `weave-codex` provider is always stripped: the single Responses `weave`
1162
- # provider supersedes it.
1115
+ # Legacy subscription providers are always stripped: the single Responses
1116
+ # `weave` provider supersedes them. Register the routing plugin when its
1117
+ # bundled source is available, while removing stale duplicate registrations.
1163
1118
  local merged
1164
1119
  if [ -f "$config_file" ]; then
1165
1120
  merged="$(jq \
1166
1121
  --argjson block "$block" \
1167
- --argjson claude "$claude_block" \
1168
1122
  --arg plugin "$plugin_arg" \
1169
- --arg pluginspec "$plugin_spec" '
1123
+ '
1170
1124
  .provider = ((.provider // {}) | .weave = $block)
1171
1125
  | (.provider |= del(."weave-codex"))
1172
- | (if $plugin != "" then .provider["weave-claude"] = $claude else .provider |= del(."weave-claude") end)
1173
- # Register the managed plugin path when we installed it; otherwise strip a
1174
- # stale entry left by a prior install (the provider was just removed, so a
1175
- # lingering plugin reference would be dead weight).
1126
+ | (.provider |= del(."weave-claude"))
1176
1127
  | (if $plugin != ""
1177
- then .plugin = ((.plugin // []) | if index($plugin) then . else . + [$plugin] end)
1128
+ then .plugin = ((.plugin // []) | map(select((tostring | endswith("/opencode-weave.ts")) | not)) + [$plugin])
1178
1129
  else (if (.plugin | type) == "array"
1179
- then (.plugin -= [$pluginspec]) | (if (.plugin | length) == 0 then del(.plugin) else . end)
1130
+ then .plugin |= map(select((tostring | endswith("/opencode-weave.ts")) | not))
1180
1131
  else . end)
1181
1132
  end)
1133
+ | (if (.plugin | type) == "array" and (.plugin | length) == 0 then del(.plugin) else . end)
1182
1134
  | .model = "weave/auto"
1183
1135
  | (.["$schema"] //= "https://opencode.ai/config.json")
1184
1136
  ' "$config_file")"
1185
1137
  else
1186
1138
  merged="$(jq -n \
1187
1139
  --argjson block "$block" \
1188
- --argjson claude "$claude_block" \
1189
- --arg plugin "$plugin_arg" '
1140
+ --arg plugin "$plugin_arg" \
1141
+ '
1190
1142
  {
1191
1143
  "$schema": "https://opencode.ai/config.json",
1192
1144
  model: "weave/auto",
1193
1145
  provider: { weave: $block }
1194
1146
  }
1195
- | (if $plugin != "" then .provider["weave-claude"] = $claude | .plugin = [$plugin] else . end)
1147
+ | (if $plugin != "" then .plugin = [$plugin] else . end)
1196
1148
  ')"
1197
1149
  fi
1198
1150
  printf '%s\n' "$merged" >"$config_file"
@@ -1853,7 +1805,8 @@ if [ "$target" = "claude" ] || [ "$target" = "opencode" ] || [ "$target" = "pi"
1853
1805
  require_cmd jq "macOS: 'brew install jq' · Debian/Ubuntu: 'sudo apt install jq'"
1854
1806
  fi
1855
1807
  # curl is used by the install/update paths' health/validate probes and by every
1856
- # `models` call; the on/off/status toggles never hit the network.
1808
+ # `models` call. The on/off toggles only ping the router best-effort after a
1809
+ # real state change (see report_client_event) and skip it when curl is absent.
1857
1810
  if [ "$mode" = "install" ] || [ "$mode" = "update" ] || [ "$mode" = "models" ]; then
1858
1811
  require_cmd curl "macOS/Linux: usually preinstalled — check your package manager"
1859
1812
  fi
@@ -2555,6 +2508,60 @@ models_endpoint_is_trusted() {
2555
2508
  return 1
2556
2509
  }
2557
2510
 
2511
+ # report_client_event ACTION tells this install's router that a state-changing
2512
+ # off/on just succeeded, so the router can log and export a lifecycle event.
2513
+ # Strictly best-effort: the toggle has already been applied, users legitimately
2514
+ # turn routing off *because* the router is unreachable, and nothing here may
2515
+ # change the exit status. Everything -- resolution included -- runs in a
2516
+ # subshell with errexit off, so no failure escapes into the caller; the POST
2517
+ # itself is detached with a short timeout and its output discarded.
2518
+ #
2519
+ # Endpoint and key come from the installed config (never the hosted defaults),
2520
+ # via the same readers `models` uses, so a self-hosted install reports to its
2521
+ # own router. For Claude Code that means the parked sidecar while off, since
2522
+ # the live settings point at Anthropic then. An explicit --base-url wins over
2523
+ # the on-disk endpoint, as it does for `models`; otherwise the same trust gate
2524
+ # applies and a checkout-supplied endpoint never receives the key. The key
2525
+ # rides in a mode-600 header file, not argv.
2526
+ report_client_event() {
2527
+ local action="$1"
2528
+ (
2529
+ set +e
2530
+ endpoint="" key="" base_src="" key_src="" headers="" body="" harness=""
2531
+ command -v curl >/dev/null 2>&1 || exit 0
2532
+ if [ "$base_url_explicit" = "true" ]; then
2533
+ endpoint="${base_url%/}"
2534
+ else
2535
+ endpoint="$(resolve_installed_endpoint)"
2536
+ fi
2537
+ [ -n "$endpoint" ] || exit 0
2538
+ key="$(read_installed_key)"
2539
+ [ -n "$key" ] || exit 0
2540
+ if [ "$target" = "claude" ]; then
2541
+ base_src="$(resolve_installed_base_source "$endpoint")"
2542
+ key_src="$(resolve_installed_key_source)"
2543
+ else
2544
+ base_src="$(models_config_file_for_target)"
2545
+ key_src="$base_src"
2546
+ fi
2547
+ models_endpoint_is_trusted "$endpoint" "$base_src" "$key_src" || exit 0
2548
+ headers="$(mktemp)" || exit 0
2549
+ chmod 600 "$headers" || { rm -f "$headers"; exit 0; }
2550
+ printf '%s: %s\n' "$router_key_header" "$key" >"$headers" || { rm -f "$headers"; exit 0; }
2551
+ # The router keys harnesses the way minted keys do: Claude Code is claude_code.
2552
+ harness="$target"
2553
+ [ "$target" = "claude" ] && harness="claude_code"
2554
+ body="$(printf '{"action":"%s","harness":"%s"}' "$action" "$harness")"
2555
+ (
2556
+ trap 'rm -f "$headers"' EXIT
2557
+ curl -sS --max-time 2 -X POST -H 'Content-Type: application/json' \
2558
+ --header "@$headers" --data-binary "$body" -o /dev/null \
2559
+ "$endpoint/v1/client-events"
2560
+ ) >/dev/null 2>&1 </dev/null &
2561
+ ) >/dev/null 2>&1 || true
2562
+ return 0
2563
+ }
2564
+
2558
2565
  # gitignore_add appends an entry to the repo .gitignore in project scope so a
2559
2566
  # parked sidecar (which may carry the router key header) never gets committed.
2560
2567
  # No-op for user scope and --dir, matching how install handles its own ignores.
@@ -2722,6 +2729,7 @@ toggle_claude() {
2722
2729
  printf '%s\n' "$merged" >"$settings_file"
2723
2730
  fi
2724
2731
  ok "Claude Code is ${C_BOLD}off${C_RESET} (direct to Anthropic). Restart Claude Code for it to take effect."
2732
+ report_client_event off
2725
2733
  ;;
2726
2734
  on)
2727
2735
  if [ "$parked_present" != "true" ]; then
@@ -2746,6 +2754,7 @@ toggle_claude() {
2746
2754
  printf '%s\n' "$merged" >"$local_settings_file"
2747
2755
  chmod 600 "$local_settings_file"
2748
2756
  ok "Claude Code is ${C_BOLD}on${C_RESET} (routing through the Weave Router). Restart Claude Code for it to take effect."
2757
+ report_client_event on
2749
2758
  else
2750
2759
  warn "Claude Code is off and the parked router key is missing (its sidecar was deleted). Re-run the installer to restore the router key — leaving the current direct-to-Anthropic setup in place so requests don't fail auth."
2751
2760
  fi
@@ -2786,6 +2795,7 @@ toggle_claude() {
2786
2795
  apply_claude_context_window on "$active"
2787
2796
  rm -f "$parked"
2788
2797
  ok "Claude Code is ${C_BOLD}on${C_RESET} (routing through the Weave Router). Restart Claude Code for it to take effect."
2798
+ report_client_event on
2789
2799
  ;;
2790
2800
  esac
2791
2801
  }
@@ -2833,6 +2843,7 @@ toggle_codex() {
2833
2843
  "$codex_status_file" --off >/dev/null 2>&1 || true
2834
2844
  fi
2835
2845
  ok "Codex is ${C_BOLD}off${C_RESET} (default provider). Takes effect on your next 'codex' run."
2846
+ report_client_event off
2836
2847
  ;;
2837
2848
  on)
2838
2849
  if [ "$state" = "absent" ]; then warn "No managed Weave block in $f. Run the installer to set up Codex."; return 0; fi
@@ -2877,6 +2888,7 @@ toggle_codex() {
2877
2888
  "$codex_status_file" --on >/dev/null 2>&1 || true
2878
2889
  fi
2879
2890
  ok "Codex is ${C_BOLD}on${C_RESET} (routing through the Weave Router). Takes effect on your next 'codex' run."
2891
+ report_client_event on
2880
2892
  ;;
2881
2893
  esac
2882
2894
  }
@@ -2933,6 +2945,7 @@ toggle_opencode() {
2933
2945
  else
2934
2946
  ok "opencode is ${C_BOLD}off${C_RESET} — choose a direct model with /models. Takes effect on your next opencode run."
2935
2947
  fi
2948
+ report_client_event off
2936
2949
  ;;
2937
2950
  on)
2938
2951
  if [ "$on" = "true" ]; then ok "opencode is already on — nothing to do."; return 0; fi
@@ -2958,6 +2971,7 @@ toggle_opencode() {
2958
2971
  chmod 600 "$parked"
2959
2972
  gitignore_add ".weave-parked.json"
2960
2973
  ok "opencode is ${C_BOLD}on${C_RESET} (default model $router_model via the Weave Router). Takes effect on your next opencode run."
2974
+ report_client_event on
2961
2975
  ;;
2962
2976
  esac
2963
2977
  }
@@ -3591,6 +3605,27 @@ if [ "$mode" = "models" ] || [ "$mode" = "accounts" ] || [ "$mode" = "login" ] |
3591
3605
  # Editing model selection needs the endpoint and key of one specific install,
3592
3606
  # never the hosted defaults: a self-hosted user pointing at their own router
3593
3607
  # would otherwise silently edit the hosted one's installation.
3608
+ # Login enrollment is client-independent. When no Claude/Codex endpoint is
3609
+ # configured, prefer the managed OpenCode config as the source for the
3610
+ # router endpoint; the provider operand still selects the account to enroll.
3611
+ if [ "$mode" = "login" ] && [ "$target" != "opencode" ] && [ "$base_url_explicit" != "true" ]; then
3612
+ login_target="$target"
3613
+ login_target_base="$(resolve_installed_endpoint)"
3614
+ if [ -z "$login_target_base" ]; then
3615
+ target="opencode"
3616
+ if [ -n "$install_dir" ]; then
3617
+ opencode_dir="$install_dir"
3618
+ elif [ "$scope" = "project" ]; then
3619
+ opencode_dir="$settings_base"
3620
+ else
3621
+ opencode_dir="${XDG_CONFIG_HOME:-$settings_base/.config}/opencode"
3622
+ fi
3623
+ opencode_config_file="$opencode_dir/opencode.json"
3624
+ if [ -z "$(resolve_installed_endpoint)" ]; then
3625
+ target="$login_target"
3626
+ fi
3627
+ fi
3628
+ fi
3594
3629
  if [ "$base_url_explicit" != "true" ]; then
3595
3630
  models_base="$(resolve_installed_endpoint)"
3596
3631
  if [ -z "$models_base" ] && { [ "$mode" = "accounts" ] || [ "$mode" = "status" ]; } && [ "$target" = "claude" ]; then
@@ -3628,6 +3663,33 @@ if [ "$mode" = "models" ] || [ "$mode" = "accounts" ] || [ "$mode" = "login" ] |
3628
3663
  models_key_source="$(models_config_file_for_target)"
3629
3664
  fi
3630
3665
  fi
3666
+ # Managed enrollment is client-independent. If an OpenCode-only install is
3667
+ # the first router config on the machine, login claude|codex still needs to
3668
+ # find its endpoint and key even though the provider operand initially makes
3669
+ # the lookup target Claude or Codex. Reuse the OpenCode key in that case, but
3670
+ # only when it pairs with the endpoint already resolved above: the endpoint
3671
+ # is either an explicit --base-url or the selected client's own install, and
3672
+ # a key from one router must never be sent to another.
3673
+ if [ "$mode" = "login" ] && [ "$target" != "opencode" ] && [ -z "$api_key" ]; then
3674
+ login_target="$target"
3675
+ target="opencode"
3676
+ if [ -n "$install_dir" ]; then
3677
+ opencode_dir="$install_dir"
3678
+ elif [ "$scope" = "project" ]; then
3679
+ opencode_dir="$settings_base"
3680
+ else
3681
+ opencode_dir="${XDG_CONFIG_HOME:-$settings_base/.config}/opencode"
3682
+ fi
3683
+ opencode_config_file="$opencode_dir/opencode.json"
3684
+ opencode_key="$(read_installed_key)"
3685
+ opencode_base="$(resolve_installed_endpoint)"
3686
+ if [ -n "$opencode_key" ] && { [ "$base_url_explicit" = "true" ] || [ "$(strip_trailing_slashes "$opencode_base")" = "$(strip_trailing_slashes "$base_url")" ]; }; then
3687
+ api_key="$opencode_key"
3688
+ models_key_source="$opencode_config_file"
3689
+ fi
3690
+ target="$login_target"
3691
+ fi
3692
+
3631
3693
  if [ -z "$api_key" ]; then
3632
3694
  err "No router key found for $target in this scope. Re-run 'npx $npm_package_name --$target', or export WEAVE_ROUTER_KEY."
3633
3695
  exit 1
@@ -5031,15 +5093,13 @@ if [ "$target" = "opencode" ]; then
5031
5093
  verify_install
5032
5094
 
5033
5095
  announce_done "opencode"
5034
- # Surface the optional subscription-routing path only when this run actually
5035
- # registered the weave-claude login provider (which is written together with
5036
- # the plugin). Gate on its presence in the written config (authoritative)
5037
- # rather than a plugin file on disk — a leftover plugin from a prior install
5038
- # can outlive a plugin-less re-install that stripped the provider, which would
5039
- # make these instructions misleading.
5040
- if jq -e '(.provider // {}) | has("weave-claude")' "$opencode_config_file" >/dev/null 2>&1; then
5041
- info "Optional: connect your AI plans so they pay for the matching turns. Run ${C_BOLD}opencode auth login${C_RESET} → ${C_BOLD}Weave Router — Codex plan${C_RESET} for ${C_BOLD}ChatGPT Pro/Plus${C_RESET} (GPT/Codex turns) and/or ${C_BOLD}Weave Router — Claude plan${C_RESET} for ${C_BOLD}Claude Pro/Max${C_RESET} (Claude turns). The router still routes every turn; your Weave key pays for the rest."
5096
+ enrollment_args=""
5097
+ if [ -n "$install_dir" ]; then
5098
+ enrollment_args=" --dir $(printf '%q' "$install_dir")"
5099
+ elif [ "$scope" = "project" ]; then
5100
+ enrollment_args=" --scope project"
5042
5101
  fi
5102
+ info "To enroll managed subscriptions, run ${C_BOLD}npx $npm_package_name login claude${enrollment_args}${C_RESET} and/or ${C_BOLD}npx $npm_package_name login codex${enrollment_args}${C_RESET}."
5043
5103
  if [ -n "$install_dir" ]; then
5044
5104
  # --dir installs land outside opencode's discovery roots, so the caller
5045
5105
  # has to point opencode at the file explicitly.
@@ -6143,7 +6203,7 @@ write_claude_settings() {
6143
6203
  jq -n --arg url "$base_url" --arg sl "$statusline_path_for_settings" --arg statusline_install "$statusline_install" '{
6144
6204
  env: { ANTHROPIC_BASE_URL: $url, ENABLE_TOOL_SEARCH: "true" },
6145
6205
  attribution: {
6146
- commit: "Co-Authored-By: Weave Router <router@workweave.ai>",
6206
+ commit: "Co-Authored-By: Weave Router <router@weaveos.com>",
6147
6207
  pr: "🤖 Generated with [Weave Router](https://router.workweave.ai)"
6148
6208
  }
6149
6209
  } + (if $statusline_install == "true" then {statusLine: { type: "command", command: $sl }} else {} end)' >"$tmp_patch"
@@ -6151,7 +6211,7 @@ write_claude_settings() {
6151
6211
  jq -n --arg url "$base_url" --arg header "$custom_headers" --arg sl "$statusline_path_for_settings" --arg statusline_install "$statusline_install" '{
6152
6212
  env: { ANTHROPIC_BASE_URL: $url, ANTHROPIC_CUSTOM_HEADERS: $header, ENABLE_TOOL_SEARCH: "true" },
6153
6213
  attribution: {
6154
- commit: "Co-Authored-By: Weave Router <router@workweave.ai>",
6214
+ commit: "Co-Authored-By: Weave Router <router@weaveos.com>",
6155
6215
  pr: "🤖 Generated with [Weave Router](https://router.workweave.ai)"
6156
6216
  }
6157
6217
  } + (if $statusline_install == "true" then {statusLine: { type: "command", command: $sl }} else {} end)' >"$tmp_patch"
@@ -1,57 +1,35 @@
1
- # opencode Weave subscription plugin
1
+ # Legacy opencode Weave integration
2
2
 
3
- Lets a caller's own **AI subscriptions** pay for their **opencode** turns, routed
4
- through the Weave Router. A subscription is a **credential scoped to the model
5
- family it can pay for**, not a provider you pick: you connect your ChatGPT
6
- (Codex) and/or Claude (Pro/Max) plan once, the router routes every request to the
7
- best model, and bills the plan that matches the model it served — ChatGPT pays
8
- for GPT/Codex turns, Claude pays for Claude turns, your Weave key pays for
9
- everything else.
3
+ This source is bundled and installed for OpenCode's lifecycle, classifier, and
4
+ directive hooks. Subscription enrollment now happens in the router with
5
+ `npx @weave-os/router login claude` or `npx @weave-os/router login codex`;
6
+ requests must not carry subscription headers.
10
7
 
11
- Bundled into `@weave-os/router`; the installer (`--opencode`) drops
12
- `src/index.ts` into the user's opencode plugins dir and writes a single
13
- Responses-format `weave` provider (plus a login-only `weave-claude` provider)
14
- into `opencode.json`.
8
+ The plugin is loaded by new installs, but it does not own subscription
9
+ enrollment or transport subscription credentials.
15
10
 
16
- ## Why a plugin (config alone can't do it)
11
+ The installer writes only the Responses-format `weave` provider into
12
+ `opencode.json`.
17
13
 
18
- opencode removed built-in subscription auth in 1.3.0 and binds OAuth to its own
19
- first-party providers, so a custom router provider can't reuse it. And
20
- subscription tokens expire hourly — a static `options.headers` string can't
21
- refresh them, nor carry two subscriptions whose tokens rotate independently.
14
+ ## Why this source remains
15
+
16
+ Older manually-installed copies may also load this module for lifecycle and
17
+ directive hooks. It intentionally contains no OAuth login, token refresh, or
18
+ subscription-header transport.
22
19
 
23
20
  ## Wire shape it produces
24
21
 
25
- opencode talks to one Responses-format `weave` provider; the plugin's loader
26
- attaches whichever subscriptions are connected to **every** request via the
27
- router's dedicated headers:
22
+ opencode talks to one Responses-format `weave` provider. Subscription enrollment
23
+ is managed by the router (`npx @weave-os/router login claude`), not by request
24
+ headers from this plugin:
28
25
 
29
26
  | | |
30
27
  |---|---|
31
28
  | `POST {router}/v1/responses` | Responses wire format (opencode's default for an `@ai-sdk/openai` provider) |
32
- | `X-Weave-OpenAI-Subscription: <ChatGPT JWT>` | pays GPT/Codex turns, refreshed on expiry |
33
- | `X-Weave-OpenAI-Account-ID: <id>` | paired account id (required by the Codex backend) |
34
- | `X-Weave-Anthropic-Subscription: <sk-ant-oat token>` | pays Claude turns, refreshed on expiry |
35
29
  | `X-Weave-Router-Key: rk_…` | from `opencode.json` `options.headers` — the router authenticates off this |
36
30
 
37
- The router routes each request across every model the caller's subs + key can pay
38
- for and resolves the subscription matching the chosen provider, so a sub is
39
- never billed for a request outside its family.
40
-
41
- ## Two storage slots, one request provider
42
-
43
- opencode stores one credential per provider id and the loader's `getAuth()` is
44
- scoped to its own provider, so the two logins live in two slots:
45
-
46
- - **`weave`** — the request provider. Owns the **ChatGPT** login and the loader
47
- that attaches both subscriptions. Connecting ChatGPT activates sub-routing.
48
- - **`weave-claude`** — login-only (no models, serves no requests). Owns the
49
- **Claude** login. Its token is read from opencode's on-disk auth store by the
50
- `weave` loader (the SDK exposes no get-by-id).
51
-
52
- With neither connected, `weave` is a plain router provider and the Weave key
53
- pays. Either login activates its matching subscription independently, so a
54
- Claude-only setup pays Claude turns from that plan without requiring ChatGPT.
31
+ The router routes each request across the models available to the managed
32
+ installation and its configured credentials.
55
33
 
56
34
  ## Router directives
57
35
 
@@ -62,17 +40,16 @@ rewrites `$rf` / `$router-feedback`, `$fm` / `$force-model`, `$ufm` /
62
40
  / `router-status` / `disable-routing`) stay CLI-only — this installer does not
63
41
  own a per-session config flip the way Claude Code and Codex do.
64
42
 
65
- ## Login
43
+ ## Enrollment
44
+
45
+ Enroll subscriptions through the managed router rather than OpenCode:
66
46
 
67
- `opencode auth login` → **Weave Router — Codex plan** → *ChatGPT Pro/Plus*
68
- (browser or headless device code) and/or **Weave Router — Claude plan** →
69
- *Claude Pro/Max* (browser; paste the `code#state` shown after authorizing).
47
+ ```sh
48
+ npx @weave-os/router login claude # or: npx @weave-os/router login codex
49
+ ```
70
50
 
71
- These logins populate OpenCode's provider-keyed `auth.json`, which is how this
72
- plugin reads and forwards the subscription credentials. The standalone
73
- `npx @weave-os/router login codex|claude` commands enroll server-side
74
- subscription accounts instead; they do not populate OpenCode's auth store and
75
- are not a replacement for these plugin logins.
51
+ The router stores and refreshes the enrollment server-side; OpenCode does not
52
+ need to carry subscription credentials in request headers.
76
53
 
77
54
  ## Env overrides (self-host + tests)
78
55
 
@@ -85,12 +62,6 @@ are not a replacement for these plugin logins.
85
62
  a new session instead. Requires a router deployment with the exact release
86
63
  and installation explicitly allowlisted. Deploy the router's non-retryable
87
64
  client-failure response before enabling this opt-in on developer machines.
88
- - `WEAVE_CODEX_OAUTH_ISSUER` — OpenAI auth issuer.
89
- - `WEAVE_ANTHROPIC_OAUTH_AUTHORIZE` / `WEAVE_ANTHROPIC_OAUTH_TOKEN` — Anthropic
90
- OAuth authorize host / token endpoint.
91
- - `WEAVE_OPENCODE_AUTH_FILE` — path to opencode's `auth.json` (the `weave`
92
- loader reads the `weave-claude` slot from here; defaults to
93
- `$XDG_DATA_HOME/opencode/auth.json`).
94
65
 
95
66
  ## Verification
96
67
 
@@ -124,11 +95,11 @@ or real providers.
124
95
 
125
96
  | Layer | Contract |
126
97
  |---|---|
127
- | Bun plugin tests | All four subscription combinations; expiry, refresh failure isolation, late login; header/session continuity; no secrets logged |
98
+ | Bun integration tests | Router/lifecycle header continuity, directive rewriting, and no subscription/account header injection |
128
99
  | Pinned Responses SDK fixtures | Streaming and non-streaming text/usage, two tool calls, upstream errors, malformed/unknown events, truncated streams, absent usage |
129
100
  | Installed real CLI | Exact `/v1/responses`, `auto`, `X-App`, router key, nonempty session IDs, parsed text, usage, completion, two executed tools and matching tool results |
130
101
  | Real lifecycle hooks | Main `build`, title `title`, task child `explore`, and automatic `compaction` followed by resumed `build`; parent/child session boundaries |
131
- | Real plugin loader | Both providers' OAuth methods visible through `opencode serve` → `/provider/auth`, even without an OAuth store |
102
+ | Real plugin loader | Routing hooks remain loadable when explicitly installed as a legacy plugin |
132
103
  | Installer/package | Install/toggle/uninstall, packed npm `--opencode` entrypoint; existing Claude/Codex/Pi installer coverage |
133
104
  | Go proxy/translation | Native and translated Responses history hygiene, actionable tool-output commands, Codex feedback-skill preservation, wire lifecycle and usage |
134
105
 
@@ -149,11 +120,9 @@ unknown token counts. These are explicit compatibility observations, **not** cla
149
120
  of clean failure or successful completion. The normal CLI cases require both a
150
121
  successful terminal event and exact usage, so removing completion/usage fails them.
151
122
 
152
- The plugin intentionally uses the
153
- [legacy all-export loader](https://github.com/anomalyco/opencode/blob/v1.18.27/packages/opencode/src/plugin/index.ts):
154
- all exported values are plugin functions, `default === WeaveCodex` is deduplicated,
155
- and `WeaveClaude` registers separately. Converting the default to a V1 plugin
156
- object would bypass those named exports; the loader tests guard against that.
123
+ The source intentionally keeps the
124
+ [legacy all-export loader](https://github.com/anomalyco/opencode/blob/v1.18.27/packages/opencode/src/plugin/index.ts)
125
+ shape required by the pinned OpenCode version.
157
126
  See the current [CLI](https://opencode.ai/docs/cli/),
158
127
  [plugin](https://opencode.ai/docs/plugins/), and
159
128
  [server](https://opencode.ai/docs/server/) references when updating the pin.
@@ -2,7 +2,7 @@
2
2
  "name": "@weave-os/router-opencode-extension",
3
3
  "private": true,
4
4
  "type": "module",
5
- "description": "The opencode subscription auth plugin bundled into @weave-os/router. NOT published separately: src/ is copied into the @weave-os/router package at prepack and dropped into the user's opencode plugin directory by install.sh --opencode. Lets a caller's own ChatGPT and Claude subscriptions pay for matching opencode turns routed through the Weave Router. This manifest marks the sources as ESM and declares the opencode peer dependency for local typecheck.",
5
+ "description": "OpenCode lifecycle, classifier, and directive hooks for @weave-os/router; managed subscription enrollment belongs to the router.",
6
6
  "scripts": {
7
7
  "test": "bun test test/",
8
8
  "typecheck": "tsc --project tsconfig.json"