@weave-os/router 0.2.19 → 0.2.20
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 +26 -18
- package/cc-statusline.sh +6 -1
- package/install.sh +314 -89
- package/opencode-weave/README.md +85 -13
- package/opencode-weave/package.json +4 -2
- package/opencode-weave/src/directives.ts +72 -0
- package/opencode-weave/src/index.ts +138 -28
- package/package.json +1 -1
- package/pi-router/README.md +69 -3
- package/pi-router/package.json +4 -4
- package/pi-router/src/compaction.ts +2 -2
- package/pi-router/src/escalation.ts +265 -0
- package/pi-router/src/index.ts +8 -4
- package/pi-router/src/ui.ts +14 -2
- package/uninstall.sh +147 -24
package/install.sh
CHANGED
|
@@ -5,17 +5,21 @@
|
|
|
5
5
|
# Configures Claude Code (default), the OpenAI Codex CLI (`--codex`),
|
|
6
6
|
# opencode (`--opencode`), or pi (`--pi`) to permanently route through the
|
|
7
7
|
# Weave Router. For Claude Code this writes the router base URL, router auth
|
|
8
|
-
# header, and a status line into Claude Code's settings.json
|
|
9
|
-
#
|
|
10
|
-
#
|
|
11
|
-
#
|
|
12
|
-
#
|
|
13
|
-
#
|
|
8
|
+
# header, and a status line into Claude Code's settings.json unless Claude Code
|
|
9
|
+
# already has an active statusline configured. For Codex it writes a
|
|
10
|
+
# `model_providers.weave` entry plus `model_provider = "weave"` into
|
|
11
|
+
# ~/.codex/config.toml (managed block delimited by markers). For opencode it
|
|
12
|
+
# merges a Responses-format `provider.weave` block into opencode.json — since
|
|
13
|
+
# the file is JSON, install/uninstall are structural (jq) rather than
|
|
14
|
+
# marker-delimited. For pi it merges a `weave` provider into
|
|
14
15
|
# ~/.pi/agent/models.json, sets it as the default in settings.json, and adds
|
|
15
16
|
# the @weave-os/router extension (which also adds a parallel subagent
|
|
16
17
|
# `dispatch` tool) — all structural (jq) merges.
|
|
17
18
|
#
|
|
18
19
|
# Two scopes (apply to all targets):
|
|
20
|
+
# --context-window 1m Opt Claude Code into its selected model's 1M variant.
|
|
21
|
+
# Preserves the prior setting for off/uninstall; never disables compaction.
|
|
22
|
+
#
|
|
19
23
|
# - user (default): ~/.claude/settings.json + ~/.weave/cc-statusline.sh
|
|
20
24
|
# ~/.codex/config.toml (with --codex)
|
|
21
25
|
# ~/.config/opencode/opencode.json (with --opencode)
|
|
@@ -48,6 +52,7 @@
|
|
|
48
52
|
# npx @weave-os/router --dir /tmp/my-sandbox # isolated throwaway install
|
|
49
53
|
# npx @weave-os/router --local # local router on localhost:8080
|
|
50
54
|
# npx @weave-os/router --base-url http://localhost:8080 # self-hosted, custom port
|
|
55
|
+
# npx @weave-os/router --email you@example.com # set the router identity email without prompting
|
|
51
56
|
# npx @weave-os/router --non-interactive # require WEAVE_ROUTER_KEY env var (defaults target to claude)
|
|
52
57
|
# npx @weave-os/router --quiet # suppress banner, ping check, and trailing tips
|
|
53
58
|
# npx @weave-os/router --rotate-key # ignore the installed key and prompt for a new one
|
|
@@ -73,11 +78,11 @@
|
|
|
73
78
|
# Cursor's base URL lives in its own settings UI (no file we own), so there's
|
|
74
79
|
# nothing to toggle here — flip "Override OpenAI Base URL" in Cursor settings.
|
|
75
80
|
#
|
|
76
|
-
# Which router
|
|
81
|
+
# Which router integrations each client gets is declared once in
|
|
77
82
|
# install/directives.tsv and installed from there: Claude Code and opencode get
|
|
78
|
-
# Markdown slash commands, Codex gets native `$name` skills
|
|
79
|
-
#
|
|
80
|
-
#
|
|
83
|
+
# Markdown slash commands, Codex gets native `$name` skills, pi registers /fm
|
|
84
|
+
# and /ufm in its extension, and Cursor is manual. See install/README.md for
|
|
85
|
+
# the full matrix.
|
|
81
86
|
#
|
|
82
87
|
# Inspect and edit which models this installation lets the router pick from —
|
|
83
88
|
# the same lists the router dashboard's settings page renders. The endpoint and
|
|
@@ -109,10 +114,13 @@ npm_package_name="${WEAVE_ROUTER_NPM_PACKAGE:-@weave-os/router}"
|
|
|
109
114
|
|
|
110
115
|
|
|
111
116
|
scope="user"
|
|
117
|
+
context_window=""
|
|
112
118
|
scope_explicit="false"
|
|
113
119
|
install_dir=""
|
|
114
120
|
base_url=""
|
|
115
121
|
base_url_explicit="false"
|
|
122
|
+
email=""
|
|
123
|
+
email_explicit="false"
|
|
116
124
|
non_interactive="false"
|
|
117
125
|
quiet="false"
|
|
118
126
|
router_key_header="X-Weave-Router-Key"
|
|
@@ -120,9 +128,9 @@ router_key_header="X-Weave-Router-Key"
|
|
|
120
128
|
# settings.json; "codex" writes ~/.codex/config.toml; "opencode" merges a
|
|
121
129
|
# provider block into opencode.json. Each target carries its own
|
|
122
130
|
# credential-passthrough story in the router: Claude Code's logged-in
|
|
123
|
-
# Anthropic key flows through unchanged, Codex's
|
|
124
|
-
# through
|
|
125
|
-
#
|
|
131
|
+
# Anthropic key flows through unchanged, Codex's ChatGPT credential flows
|
|
132
|
+
# through its native provider, and opencode uses the Responses API plus
|
|
133
|
+
# dedicated subscription headers. target_explicit tracks whether
|
|
126
134
|
# --claude / --codex / --opencode was passed so an interactive run can
|
|
127
135
|
# prompt for the choice.
|
|
128
136
|
target="claude"
|
|
@@ -362,6 +370,37 @@ refuse_if_symlink() {
|
|
|
362
370
|
fi
|
|
363
371
|
}
|
|
364
372
|
|
|
373
|
+
# The marker is part of the installed script, so a user-owned script at the
|
|
374
|
+
# same conventional path can be distinguished from one managed by the router.
|
|
375
|
+
CLAUDE_STATUSLINE_MARKER="# Claude Code statusline for the Weave Router."
|
|
376
|
+
|
|
377
|
+
# claude_statusline_configured reports whether Claude Code has a non-null
|
|
378
|
+
# statusline setting in a settings file.
|
|
379
|
+
claude_statusline_configured() {
|
|
380
|
+
local settings_path="$1"
|
|
381
|
+
[ -f "$settings_path" ] || return 1
|
|
382
|
+
jq -e 'has("statusLine") and (.statusLine != null)' "$settings_path" >/dev/null 2>&1
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
# claude_statusline_router_owned reports whether a settings entry points at the
|
|
386
|
+
# router's statusline. Existing scripts prove ownership with the marker; when a
|
|
387
|
+
# script is missing, the adjacent ownership marker proves that the router wrote
|
|
388
|
+
# it and should recreate it.
|
|
389
|
+
claude_statusline_router_owned() {
|
|
390
|
+
local settings_path="$1" expected_command="$2" script_path="$3" ownership_marker_path="$4" configured_command
|
|
391
|
+
[ -f "$settings_path" ] || return 1
|
|
392
|
+
configured_command="$(jq -r '.statusLine.command // empty' "$settings_path" 2>/dev/null || true)"
|
|
393
|
+
[ "$configured_command" = "$expected_command" ] || return 1
|
|
394
|
+
if [ -f "$script_path" ]; then
|
|
395
|
+
if grep -Fq "$CLAUDE_STATUSLINE_MARKER" "$script_path" 2>/dev/null; then
|
|
396
|
+
return 0
|
|
397
|
+
fi
|
|
398
|
+
[ -r "$script_path" ] && return 1
|
|
399
|
+
fi
|
|
400
|
+
[ -f "$ownership_marker_path" ] \
|
|
401
|
+
&& grep -Fq "$CLAUDE_STATUSLINE_MARKER" "$ownership_marker_path"
|
|
402
|
+
}
|
|
403
|
+
|
|
365
404
|
# Markers that delimit the block this installer manages inside Codex's
|
|
366
405
|
# config.toml. Kept on disk verbatim so a re-install (or uninstall.sh
|
|
367
406
|
# --codex) can find and replace the block instead of duplicating it.
|
|
@@ -430,12 +469,20 @@ normalize_name() {
|
|
|
430
469
|
|
|
431
470
|
# resolve_user_email picks the email to plant in router request headers so the
|
|
432
471
|
# router can attribute traffic to a person even on shared API keys. Priority:
|
|
433
|
-
# WEAVE_USER_EMAIL env override → git config user.email →
|
|
434
|
-
# (pre-filled with whatever we found). In --non-interactive
|
|
435
|
-
# prompt, so unset/invalid means we ship no header (router treats
|
|
436
|
-
# account_uuid-only, same as today). Echoes the validated email on stdout.
|
|
472
|
+
# explicit --email → WEAVE_USER_EMAIL env override → git config user.email →
|
|
473
|
+
# interactive prompt (pre-filled with whatever we found). In --non-interactive
|
|
474
|
+
# mode we never prompt, so unset/invalid means we ship no header (router treats
|
|
475
|
+
# that as account_uuid-only, same as today). Echoes the validated email on stdout.
|
|
437
476
|
resolve_user_email() {
|
|
438
477
|
local candidate=""
|
|
478
|
+
if [ "$email_explicit" = "true" ]; then
|
|
479
|
+
candidate="$(normalize_email "$email")"
|
|
480
|
+
if [ -z "$candidate" ]; then
|
|
481
|
+
warn "--email=\"$email\" is not a valid email; ignoring."
|
|
482
|
+
fi
|
|
483
|
+
printf '%s' "$candidate"
|
|
484
|
+
return
|
|
485
|
+
fi
|
|
439
486
|
if [ -n "${WEAVE_USER_EMAIL:-}" ]; then
|
|
440
487
|
candidate="$(normalize_email "$WEAVE_USER_EMAIL")"
|
|
441
488
|
if [ -z "$candidate" ]; then
|
|
@@ -911,6 +958,9 @@ write_opencode_config() {
|
|
|
911
958
|
# upstream model for every request, so presenting pinned model names would
|
|
912
959
|
# imply a choice that the router intentionally does not honor. Whichever
|
|
913
960
|
# model serves a turn uses its matching subscription when one is connected.
|
|
961
|
+
# OpenCode interprets omitted custom-model limits as zero, which disables its
|
|
962
|
+
# overflow compaction. The 128K/32K virtual contract is the router's
|
|
963
|
+
# conservative compatibility floor and leaves 96K for model-visible input.
|
|
914
964
|
#
|
|
915
965
|
# npm is @ai-sdk/openai and baseURL KEEPS its /v1 here: opencode's
|
|
916
966
|
# @ai-sdk/openai provider appends /responses, yielding the router's
|
|
@@ -927,10 +977,16 @@ write_opencode_config() {
|
|
|
927
977
|
--argjson headers "$headers_json" '
|
|
928
978
|
{
|
|
929
979
|
npm: "@ai-sdk/openai",
|
|
930
|
-
name: "Weave Router",
|
|
980
|
+
name: "Weave Router — Codex plan",
|
|
931
981
|
options: { apiKey: $key, baseURL: $url, headers: $headers },
|
|
932
982
|
models: {
|
|
933
|
-
auto: {
|
|
983
|
+
auto: {
|
|
984
|
+
name: "Auto",
|
|
985
|
+
reasoning: true,
|
|
986
|
+
attachment: true,
|
|
987
|
+
modalities: { input: ["text", "image", "pdf"], output: ["text"] },
|
|
988
|
+
limit: { context: 128000, output: 32000 }
|
|
989
|
+
}
|
|
934
990
|
}
|
|
935
991
|
}
|
|
936
992
|
')"
|
|
@@ -969,20 +1025,43 @@ write_opencode_config() {
|
|
|
969
1025
|
plugin_dir="$(cd "$(dirname "$config_file")" && pwd)/.weave"
|
|
970
1026
|
plugin_spec="$plugin_dir/opencode-weave.ts"
|
|
971
1027
|
plugin_src="$script_dir/opencode-weave/src/index.ts"
|
|
1028
|
+
plugin_directives_src="$script_dir/opencode-weave/src/directives.ts"
|
|
972
1029
|
if [ -f "$plugin_src" ]; then
|
|
973
1030
|
mkdir -p "$plugin_dir"
|
|
974
1031
|
cp "$plugin_src" "$plugin_spec"
|
|
975
1032
|
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
|
|
976
1037
|
plugin_arg="$plugin_spec"
|
|
977
1038
|
else
|
|
978
1039
|
warn "opencode subscription plugin source not found at $plugin_src — skipping the Claude login + subscription routing. (Use a packaged 'npx $npm_package_name' install.)"
|
|
979
1040
|
fi
|
|
980
1041
|
|
|
1042
|
+
# Installing must actually activate the router. Preserve a prior direct model
|
|
1043
|
+
# beside the config so off/uninstall can restore the user's exact choice.
|
|
1044
|
+
local parked_file previous_model
|
|
1045
|
+
parked_file="$(dirname "$config_file")/.weave-parked.json"
|
|
1046
|
+
if [ -f "$config_file" ]; then
|
|
1047
|
+
previous_model="$(json_get "$config_file" '.model')"
|
|
1048
|
+
case "$previous_model" in
|
|
1049
|
+
""|weave/*|weave-codex/*|weave-claude/*) ;;
|
|
1050
|
+
*)
|
|
1051
|
+
if [ "$scope" = "project" ] || [ -n "$install_dir" ]; then
|
|
1052
|
+
refuse_if_symlink "$parked_file"
|
|
1053
|
+
fi
|
|
1054
|
+
jq -n --arg direct "$previous_model" --arg router "weave/auto" \
|
|
1055
|
+
'{direct_model: $direct, router_model: $router}' >"$parked_file"
|
|
1056
|
+
chmod 600 "$parked_file"
|
|
1057
|
+
;;
|
|
1058
|
+
esac
|
|
1059
|
+
fi
|
|
1060
|
+
|
|
981
1061
|
# Merge into any existing opencode.json. We always overwrite provider.weave
|
|
982
1062
|
# so re-install reflects the latest key/identity, but we leave the rest of the
|
|
983
|
-
# file (other providers, mcp, agent settings) untouched.
|
|
984
|
-
#
|
|
985
|
-
# choices stay untouched.
|
|
1063
|
+
# file (other providers, mcp, agent settings) untouched. The managed model is
|
|
1064
|
+
# always weave/auto; a prior direct choice was parked above for exact restore.
|
|
986
1065
|
#
|
|
987
1066
|
# The weave-claude login provider AND the plugin entry are written together
|
|
988
1067
|
# only when the bundled plugin was present and copied ($plugin non-empty): the
|
|
@@ -1010,12 +1089,7 @@ write_opencode_config() {
|
|
|
1010
1089
|
then (.plugin -= [$pluginspec]) | (if (.plugin | length) == 0 then del(.plugin) else . end)
|
|
1011
1090
|
else . end)
|
|
1012
1091
|
end)
|
|
1013
|
-
|
|
|
1014
|
-
# Replace any legacy Weave model choice with the single auto-routing
|
|
1015
|
-
# choice. Models from unrelated providers remain unchanged.
|
|
1016
|
-
| (if (.model // "" | tostring) as $model
|
|
1017
|
-
| ($model | startswith("weave/") or startswith("weave-codex/") or startswith("weave-claude/"))
|
|
1018
|
-
then .model = "weave/auto" else . end)
|
|
1092
|
+
| .model = "weave/auto"
|
|
1019
1093
|
| (.["$schema"] //= "https://opencode.ai/config.json")
|
|
1020
1094
|
' "$config_file")"
|
|
1021
1095
|
else
|
|
@@ -1301,11 +1375,21 @@ while [ $# -gt 0 ]; do
|
|
|
1301
1375
|
[ "$scope" = "user" ] || [ "$scope" = "project" ] || { err "--scope must be 'user' or 'project'."; exit 2; }
|
|
1302
1376
|
scope_explicit="true"
|
|
1303
1377
|
;;
|
|
1378
|
+
--context-window)
|
|
1379
|
+
context_window="${2:-}"
|
|
1380
|
+
[ "$context_window" = "1m" ] || { err "--context-window requires '1m'."; exit 2; }
|
|
1381
|
+
shift 2
|
|
1382
|
+
;;
|
|
1304
1383
|
--base-url)
|
|
1305
1384
|
base_url="${2:-}"; shift 2
|
|
1306
1385
|
[ -n "$base_url" ] || { err "--base-url requires a value."; exit 2; }
|
|
1307
1386
|
base_url_explicit="true"
|
|
1308
1387
|
;;
|
|
1388
|
+
--email)
|
|
1389
|
+
email="${2:-}"; shift 2
|
|
1390
|
+
[ -n "$email" ] || { err "--email requires a value."; exit 2; }
|
|
1391
|
+
email_explicit="true"
|
|
1392
|
+
;;
|
|
1309
1393
|
--local)
|
|
1310
1394
|
# Shorthand for local dev: localhost:8080 (matches `wv mr` / `make dev` default PORT).
|
|
1311
1395
|
base_url="http://localhost:8080"
|
|
@@ -1399,6 +1483,14 @@ while [ $# -gt 0 ]; do
|
|
|
1399
1483
|
esac
|
|
1400
1484
|
done
|
|
1401
1485
|
|
|
1486
|
+
if [ -n "$context_window" ]; then
|
|
1487
|
+
if [ "$target" != "claude" ] || { [ "$mode" != "install" ] && [ "$mode" != "update" ]; }; then
|
|
1488
|
+
err "--context-window is supported only for Claude Code install/update."
|
|
1489
|
+
exit 2
|
|
1490
|
+
fi
|
|
1491
|
+
target_explicit="true"
|
|
1492
|
+
fi
|
|
1493
|
+
|
|
1402
1494
|
if [ "$mode" = "setup" ]; then
|
|
1403
1495
|
if [ "$setup_claude" != "true" ] && [ "$setup_codex" != "true" ]; then
|
|
1404
1496
|
setup_claude="true"
|
|
@@ -1410,6 +1502,7 @@ if [ "$mode" = "setup" ]; then
|
|
|
1410
1502
|
setup_args=(--scope "$scope")
|
|
1411
1503
|
[ "$non_interactive" = "true" ] && setup_args+=(--non-interactive)
|
|
1412
1504
|
[ "$base_url_explicit" = "true" ] && setup_args+=(--base-url "$base_url")
|
|
1505
|
+
[ "$email_explicit" = "true" ] && setup_args+=(--email "$email")
|
|
1413
1506
|
[ -n "$install_dir" ] && setup_args+=(--dir "$install_dir")
|
|
1414
1507
|
[ "$quiet" = "true" ] && setup_args+=(--quiet)
|
|
1415
1508
|
[ "$rotate_key" = "true" ] && setup_args+=(--rotate-key)
|
|
@@ -1831,6 +1924,10 @@ else
|
|
|
1831
1924
|
fi
|
|
1832
1925
|
|
|
1833
1926
|
if [ "$target" = "claude" ]; then
|
|
1927
|
+
statusline_install="true"
|
|
1928
|
+
statusline_source_file=""
|
|
1929
|
+
statusline_expected_command=""
|
|
1930
|
+
statusline_candidate_file=""
|
|
1834
1931
|
case "$scope" in
|
|
1835
1932
|
user)
|
|
1836
1933
|
settings_dir="$settings_base/.claude"
|
|
@@ -1855,6 +1952,37 @@ if [ "$target" = "claude" ]; then
|
|
|
1855
1952
|
fi
|
|
1856
1953
|
;;
|
|
1857
1954
|
esac
|
|
1955
|
+
statusline_ownership_file="$statusline_file.weave-router"
|
|
1956
|
+
|
|
1957
|
+
# Check the effective settings layer. A user-owned statusline blocks the
|
|
1958
|
+
# install; a router-owned one is refreshed so reinstall repairs its script.
|
|
1959
|
+
if [ "$scope" = "project" ] \
|
|
1960
|
+
&& claude_statusline_configured "$local_settings_file"; then
|
|
1961
|
+
statusline_source_file="$local_settings_file"
|
|
1962
|
+
statusline_expected_command="$statusline_path_for_settings"
|
|
1963
|
+
statusline_candidate_file="$statusline_file"
|
|
1964
|
+
elif claude_statusline_configured "$settings_file"; then
|
|
1965
|
+
statusline_source_file="$settings_file"
|
|
1966
|
+
statusline_expected_command="$statusline_path_for_settings"
|
|
1967
|
+
statusline_candidate_file="$statusline_file"
|
|
1968
|
+
elif [ "$scope" = "project" ] \
|
|
1969
|
+
&& claude_statusline_configured "$HOME/.claude/settings.json"; then
|
|
1970
|
+
statusline_source_file="$HOME/.claude/settings.json"
|
|
1971
|
+
statusline_expected_command="$HOME/.weave/cc-statusline.sh"
|
|
1972
|
+
statusline_candidate_file="$HOME/.weave/cc-statusline.sh"
|
|
1973
|
+
fi
|
|
1974
|
+
if [ -n "$statusline_source_file" ] \
|
|
1975
|
+
&& ! claude_statusline_router_owned \
|
|
1976
|
+
"$statusline_source_file" "$statusline_expected_command" \
|
|
1977
|
+
"$statusline_candidate_file" "$statusline_candidate_file.weave-router"; then
|
|
1978
|
+
statusline_install="false"
|
|
1979
|
+
skip "Existing Claude Code statusline detected; leaving it unchanged."
|
|
1980
|
+
fi
|
|
1981
|
+
if [ "$statusline_install" = "true" ] \
|
|
1982
|
+
&& [ -f "$statusline_candidate_file" ] \
|
|
1983
|
+
&& [ ! -w "$statusline_candidate_file" ]; then
|
|
1984
|
+
chmod u+rw "$statusline_candidate_file"
|
|
1985
|
+
fi
|
|
1858
1986
|
|
|
1859
1987
|
# Symlink containment: refuse if any target path is a symlink. User-scope
|
|
1860
1988
|
# paths under $HOME are trusted; project-scope and --dir paths come from a
|
|
@@ -1863,10 +1991,16 @@ if [ "$target" = "claude" ]; then
|
|
|
1863
1991
|
refuse_if_symlink "$settings_dir"
|
|
1864
1992
|
refuse_if_symlink "$settings_file"
|
|
1865
1993
|
refuse_if_symlink "$local_settings_file"
|
|
1866
|
-
|
|
1994
|
+
if [ "$statusline_install" = "true" ]; then
|
|
1995
|
+
refuse_if_symlink "$statusline_file"
|
|
1996
|
+
refuse_if_symlink "$statusline_ownership_file"
|
|
1997
|
+
fi
|
|
1867
1998
|
fi
|
|
1868
1999
|
|
|
1869
|
-
mkdir -p "$settings_dir"
|
|
2000
|
+
mkdir -p "$settings_dir"
|
|
2001
|
+
if [ "$statusline_install" = "true" ]; then
|
|
2002
|
+
mkdir -p "$statusline_dir"
|
|
2003
|
+
fi
|
|
1870
2004
|
elif [ "$target" = "codex" ]; then
|
|
1871
2005
|
# Codex CLI reads config from ~/.codex/config.toml by default. For project
|
|
1872
2006
|
# scope we write to <repo>/.codex/config.toml; the user invokes Codex with
|
|
@@ -2319,6 +2453,74 @@ gitignore_add() {
|
|
|
2319
2453
|
fi
|
|
2320
2454
|
}
|
|
2321
2455
|
|
|
2456
|
+
prepare_claude_context_window() {
|
|
2457
|
+
context_settings_file="$settings_file"
|
|
2458
|
+
if [ "$scope" = "project" ] && [ -z "$install_dir" ]; then
|
|
2459
|
+
context_settings_file="$local_settings_file"
|
|
2460
|
+
fi
|
|
2461
|
+
context_state_file="$settings_dir/.weave-context-window.json"
|
|
2462
|
+
refuse_if_symlink "$context_state_file"
|
|
2463
|
+
[ -n "$context_window" ] || return 0
|
|
2464
|
+
|
|
2465
|
+
local source model="" disabled="${CLAUDE_CODE_DISABLE_1M_CONTEXT:-}" env_model="${ANTHROPIC_MODEL:-}"
|
|
2466
|
+
# Highest-priority settings first; project opt-in is written only locally.
|
|
2467
|
+
for source in "$context_settings_file" "$settings_file" "$HOME/.claude/settings.json"; do
|
|
2468
|
+
[ -f "$source" ] || continue
|
|
2469
|
+
[ -n "$model" ] || model="$(json_get "$source" '.model')"
|
|
2470
|
+
[ -n "$disabled" ] || disabled="$(json_get "$source" '.env.CLAUDE_CODE_DISABLE_1M_CONTEXT')"
|
|
2471
|
+
[ -n "$env_model" ] || env_model="$(json_get "$source" '.env.ANTHROPIC_MODEL')"
|
|
2472
|
+
done
|
|
2473
|
+
if [ -n "$disabled" ] && [ "$disabled" != "0" ] && [ "$disabled" != "false" ]; then
|
|
2474
|
+
err "1M context is disabled in your Claude Code settings; remove that opt-out before using --context-window."
|
|
2475
|
+
return 1
|
|
2476
|
+
fi
|
|
2477
|
+
if [ -n "$env_model" ]; then
|
|
2478
|
+
err "ANTHROPIC_MODEL overrides the model setting. Select its [1m] variant there instead; leaving it unchanged."
|
|
2479
|
+
return 1
|
|
2480
|
+
fi
|
|
2481
|
+
model="${model:-sonnet}"
|
|
2482
|
+
case "$model" in
|
|
2483
|
+
*'[1m]') context_window=""; return 0 ;;
|
|
2484
|
+
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) ;;
|
|
2485
|
+
*) err "Cannot assert 1M support for '$model'. Select a supported Sonnet/Opus/Fable model first; leaving it unchanged."; return 1 ;;
|
|
2486
|
+
esac
|
|
2487
|
+
context_managed_model="${model}[1m]"
|
|
2488
|
+
}
|
|
2489
|
+
|
|
2490
|
+
apply_claude_context_window() {
|
|
2491
|
+
local action="$1" active="$2" state="$settings_dir/.weave-context-window.json" merged tmp
|
|
2492
|
+
refuse_if_symlink "$state"
|
|
2493
|
+
[ -f "$active" ] || return 0
|
|
2494
|
+
if [ "$action" = "install" ] && [ -n "$context_window" ]; then
|
|
2495
|
+
tmp="$(mktemp "$settings_dir/.weave-context.XXXXXX")"
|
|
2496
|
+
jq --arg managed "$context_managed_model" '{had_model: has("model"), original: .model, managed: $managed}' "$active" >"$tmp"
|
|
2497
|
+
chmod 600 "$tmp"
|
|
2498
|
+
mv "$tmp" "$state"
|
|
2499
|
+
merged="$(jq --arg model "$context_managed_model" '.model = $model' "$active")"
|
|
2500
|
+
else
|
|
2501
|
+
[ -f "$state" ] || return 0
|
|
2502
|
+
merged="$(jq --slurpfile state "$state" --arg action "$action" '
|
|
2503
|
+
$state[0] as $s |
|
|
2504
|
+
if $action == "off" then
|
|
2505
|
+
if .model == $s.managed then
|
|
2506
|
+
if $s.had_model then .model = $s.original else del(.model) end
|
|
2507
|
+
else . end
|
|
2508
|
+
elif has("model") == $s.had_model and .model == $s.original then .model = $s.managed
|
|
2509
|
+
else . end
|
|
2510
|
+
' "$active")"
|
|
2511
|
+
fi
|
|
2512
|
+
tmp="$(mktemp "$settings_dir/.weave-context.XXXXXX")"
|
|
2513
|
+
printf '%s\n' "$merged" >"$tmp"
|
|
2514
|
+
chmod 600 "$tmp"
|
|
2515
|
+
mv "$tmp" "$active"
|
|
2516
|
+
if [ "$action" = "install" ] && [ -n "$context_window" ]; then
|
|
2517
|
+
ok "Claude Code model set to $context_managed_model; automatic compaction stays enabled. Restart Claude Code."
|
|
2518
|
+
if [ "$scope" = "project" ] && [ -z "$install_dir" ]; then
|
|
2519
|
+
gitignore_add ".claude/.weave-context-window.json"
|
|
2520
|
+
fi
|
|
2521
|
+
fi
|
|
2522
|
+
}
|
|
2523
|
+
|
|
2322
2524
|
toggle_claude() {
|
|
2323
2525
|
local parked="$settings_dir/.weave-parked.json"
|
|
2324
2526
|
local proj="false" active committed_base local_base parked_env merged
|
|
@@ -2382,6 +2584,7 @@ toggle_claude() {
|
|
|
2382
2584
|
info "Claude Code isn't configured for the router. Run the installer first."
|
|
2383
2585
|
return 0
|
|
2384
2586
|
fi
|
|
2587
|
+
apply_claude_context_window off "$active"
|
|
2385
2588
|
if [ "$proj" = "true" ]; then
|
|
2386
2589
|
# Park the whole local env (carries the key header), then override the
|
|
2387
2590
|
# base URL to Anthropic in the local file only — committed settings.json
|
|
@@ -2467,6 +2670,7 @@ toggle_claude() {
|
|
|
2467
2670
|
merged="$(jq --argjson p "$parked_env" '.env = (((.env // {}) | del(.ANTHROPIC_BASE_URL)) + $p)' "$active")"
|
|
2468
2671
|
printf '%s\n' "$merged" >"$active"
|
|
2469
2672
|
[ "$proj" = "true" ] && chmod 600 "$active"
|
|
2673
|
+
apply_claude_context_window on "$active"
|
|
2470
2674
|
rm -f "$parked"
|
|
2471
2675
|
ok "Claude Code is ${C_BOLD}on${C_RESET} (routing through the Weave Router). Restart Claude Code for it to take effect."
|
|
2472
2676
|
;;
|
|
@@ -2534,20 +2738,22 @@ toggle_codex() {
|
|
|
2534
2738
|
|
|
2535
2739
|
toggle_opencode() {
|
|
2536
2740
|
local f="$opencode_config_file" parked="$opencode_dir/.weave-parked.json"
|
|
2537
|
-
local model="" has_weave="false" parked_present="false" on="false"
|
|
2741
|
+
local model="" direct_model="" router_model="weave/auto" has_weave="false" parked_present="false" on="false" merged model_id
|
|
2538
2742
|
# Symlink containment for the parked sidecar — `off` writes it via shell
|
|
2539
2743
|
# redirection; a hostile project repo could pre-place it as a symlink. The
|
|
2540
2744
|
# opencode.json itself is already guarded during path resolution.
|
|
2541
2745
|
if [ "$scope" = "project" ] || [ -n "$install_dir" ]; then
|
|
2542
2746
|
refuse_if_symlink "$parked"
|
|
2543
2747
|
fi
|
|
2544
|
-
if [ -f "$parked" ]; then
|
|
2748
|
+
if [ -f "$parked" ]; then
|
|
2749
|
+
parked_present="true"
|
|
2750
|
+
direct_model="$(json_get "$parked" '.direct_model')"
|
|
2751
|
+
router_model="$(jq -r '.router_model // .model // "weave/auto"' "$parked" 2>/dev/null || echo "weave/auto")"
|
|
2752
|
+
fi
|
|
2545
2753
|
if [ -f "$f" ]; then
|
|
2546
|
-
model="$(
|
|
2754
|
+
model="$(json_get "$f" '.model')"
|
|
2547
2755
|
if [ "$(jq -r '((.provider // {}) | has("weave"))' "$f" 2>/dev/null || true)" = "true" ]; then has_weave="true"; fi
|
|
2548
2756
|
fi
|
|
2549
|
-
# A managed model counts as router-on: the Responses-shaped `weave/…` default,
|
|
2550
|
-
# or a legacy `weave-codex/…` model parked by a pre-upgrade install.
|
|
2551
2757
|
case "$model" in weave/* | weave-codex/*) on="true" ;; esac
|
|
2552
2758
|
|
|
2553
2759
|
case "$mode" in
|
|
@@ -2565,52 +2771,48 @@ toggle_opencode() {
|
|
|
2565
2771
|
if [ "$has_weave" = "true" ]; then ok "opencode is already off — nothing to do."; else info "opencode isn't configured for the router. Run the installer first."; fi
|
|
2566
2772
|
return 0
|
|
2567
2773
|
fi
|
|
2568
|
-
|
|
2774
|
+
router_model="$model"
|
|
2775
|
+
jq -n --arg direct "$direct_model" --arg router "$router_model" \
|
|
2776
|
+
'{direct_model: $direct, router_model: $router}' >"$parked"
|
|
2569
2777
|
chmod 600 "$parked"
|
|
2570
|
-
|
|
2778
|
+
if [ -n "$direct_model" ]; then
|
|
2779
|
+
merged="$(jq --arg model "$direct_model" '.model = $model' "$f")"
|
|
2780
|
+
else
|
|
2781
|
+
merged="$(jq 'del(.model)' "$f")"
|
|
2782
|
+
fi
|
|
2571
2783
|
printf '%s\n' "$merged" >"$f"
|
|
2572
2784
|
chmod 600 "$f"
|
|
2573
2785
|
gitignore_add ".weave-parked.json"
|
|
2574
|
-
|
|
2786
|
+
if [ -n "$direct_model" ]; then
|
|
2787
|
+
ok "opencode is ${C_BOLD}off${C_RESET} — restored $direct_model. Takes effect on your next opencode run."
|
|
2788
|
+
else
|
|
2789
|
+
ok "opencode is ${C_BOLD}off${C_RESET} — choose a direct model with /models. Takes effect on your next opencode run."
|
|
2790
|
+
fi
|
|
2575
2791
|
;;
|
|
2576
2792
|
on)
|
|
2577
2793
|
if [ "$on" = "true" ]; then ok "opencode is already on — nothing to do."; return 0; fi
|
|
2578
|
-
|
|
2579
|
-
|
|
2580
|
-
|
|
2581
|
-
elif [ "$has_weave" != "true" ]; then
|
|
2582
|
-
warn "opencode isn't configured for the router. Run the installer first."; return 0
|
|
2583
|
-
else
|
|
2584
|
-
# No parked model (sidecar deleted by hand). Derive the default from the
|
|
2585
|
-
# installed provider.weave.models block rather than a hardcoded literal
|
|
2586
|
-
# that silently diverges when the installer's default changes — prefer
|
|
2587
|
-
# the auto-routing entry, else the first model the installer registered.
|
|
2588
|
-
restore_model="$(jq -r '
|
|
2589
|
-
(.provider.weave.models // {} | keys) as $k
|
|
2590
|
-
| (([$k[] | select(. == "auto")] | first) // $k[0] // "auto")
|
|
2591
|
-
| "weave/" + .
|
|
2592
|
-
' "$f" 2>/dev/null || echo "weave/auto")"
|
|
2794
|
+
if [ "$has_weave" != "true" ]; then
|
|
2795
|
+
warn "opencode isn't configured for the router. Run the installer first."
|
|
2796
|
+
return 0
|
|
2593
2797
|
fi
|
|
2594
|
-
|
|
2595
|
-
|
|
2596
|
-
case "$restore_model" in
|
|
2798
|
+
case "$model" in ""|weave/*|weave-codex/*) ;; *) direct_model="$model" ;; esac
|
|
2799
|
+
case "$router_model" in
|
|
2597
2800
|
weave/*)
|
|
2598
|
-
|
|
2801
|
+
model_id="${router_model#weave/}"
|
|
2599
2802
|
if ! jq -e --arg id "$model_id" '(.provider.weave.models // {}) | has($id)' "$f" >/dev/null 2>&1; then
|
|
2600
|
-
|
|
2601
|
-
fi
|
|
2602
|
-
;;
|
|
2603
|
-
weave-codex/*)
|
|
2604
|
-
if [ "$(jq -r '((.provider // {}) | has("weave-codex"))' "$f" 2>/dev/null || true)" != "true" ]; then
|
|
2605
|
-
restore_model="weave/auto"
|
|
2803
|
+
router_model="weave/auto"
|
|
2606
2804
|
fi
|
|
2607
2805
|
;;
|
|
2806
|
+
*) router_model="weave/auto" ;;
|
|
2608
2807
|
esac
|
|
2609
|
-
merged="$(jq --arg
|
|
2808
|
+
merged="$(jq --arg model "$router_model" '.model = $model' "$f")"
|
|
2610
2809
|
printf '%s\n' "$merged" >"$f"
|
|
2611
2810
|
chmod 600 "$f"
|
|
2612
|
-
|
|
2613
|
-
|
|
2811
|
+
jq -n --arg direct "$direct_model" --arg router "$router_model" \
|
|
2812
|
+
'{direct_model: $direct, router_model: $router}' >"$parked"
|
|
2813
|
+
chmod 600 "$parked"
|
|
2814
|
+
gitignore_add ".weave-parked.json"
|
|
2815
|
+
ok "opencode is ${C_BOLD}on${C_RESET} (default model $router_model via the Weave Router). Takes effect on your next opencode run."
|
|
2614
2816
|
;;
|
|
2615
2817
|
esac
|
|
2616
2818
|
}
|
|
@@ -3464,28 +3666,37 @@ EOF
|
|
|
3464
3666
|
src="$commands_src_dir/$cmd.md"
|
|
3465
3667
|
dst="$dst_dir/$cmd.md"
|
|
3466
3668
|
[ -f "$src" ] || continue
|
|
3467
|
-
if [ "$scope" = "project" ] || [ -n "$install_dir" ]; then
|
|
3468
|
-
refuse_if_symlink "$dst"
|
|
3469
|
-
fi
|
|
3470
3669
|
# Substitute the {{SCOPE}} placeholder (only the router-* wrappers carry it;
|
|
3471
3670
|
# cp-equivalent for the others since the token is absent).
|
|
3472
3671
|
local body; body="$(cat "$src")"
|
|
3473
3672
|
body="${body//\{\{SCOPE\}\}/$scope_args}"
|
|
3673
|
+
ownership_file="$dst.weave-router"
|
|
3674
|
+
if [ "$scope" = "project" ] || [ -n "$install_dir" ]; then
|
|
3675
|
+
refuse_if_symlink "$dst"
|
|
3676
|
+
refuse_if_symlink "$ownership_file"
|
|
3677
|
+
fi
|
|
3474
3678
|
# Wrappers installed before ownership markers existed carry no marker. A
|
|
3475
3679
|
# file whose body still matches what this installer would write is one of
|
|
3476
3680
|
# ours from an older version, so adopt it rather than treating it as
|
|
3477
3681
|
# user-owned — otherwise every pre-marker install is stranded: never
|
|
3478
3682
|
# refreshed, never uninstalled, and skipped by the statusline refresh.
|
|
3479
|
-
#
|
|
3683
|
+
# The sidecar comparison also recognizes a router-owned wrapper after its
|
|
3684
|
+
# bundled body changes, while a user edit breaks that comparison.
|
|
3480
3685
|
if [ -e "$dst" ] && { [ ! -f "$dst" ] || ! grep -Fq "<!-- weave-router managed command: $cmd -->" "$dst"; }; then
|
|
3481
3686
|
if [ -f "$dst" ] && [ "$(cat "$dst")" = "$body" ]; then
|
|
3482
3687
|
: # an unmarked copy of our own wrapper; fall through and adopt it
|
|
3688
|
+
elif [ -f "$ownership_file" ] \
|
|
3689
|
+
&& [ "$(sed -n '1p' "$ownership_file")" = "weave-router managed command: $cmd" ] \
|
|
3690
|
+
&& [ "$(sed '1d' "$ownership_file")" = "$(cat "$dst")" ]; then
|
|
3691
|
+
: # a markerless wrapper whose sidecar still matches its body
|
|
3483
3692
|
else
|
|
3484
3693
|
warn "A user-owned $target command already exists at $dst; leaving it untouched."
|
|
3485
3694
|
continue
|
|
3486
3695
|
fi
|
|
3487
3696
|
fi
|
|
3488
|
-
printf '%s\n
|
|
3697
|
+
printf '%s\n' "$body" >"$dst"
|
|
3698
|
+
# Keep ownership metadata in a sidecar so Claude Code never sends it as prompt text.
|
|
3699
|
+
printf 'weave-router managed command: %s\n%s\n' "$cmd" "$body" >"$ownership_file"
|
|
3489
3700
|
done
|
|
3490
3701
|
seed_command_baseline "$commands_src_dir" "$cmds"
|
|
3491
3702
|
ok "Slash commands written to $dst_dir ($installed)"
|
|
@@ -4486,7 +4697,6 @@ if [ "$target" = "codex" ]; then
|
|
|
4486
4697
|
ok "Codex config written to $codex_config_file"
|
|
4487
4698
|
remove_obsolete_codex_prompt_wrappers "$codex_dir/prompts"
|
|
4488
4699
|
install_codex_prompt_skills
|
|
4489
|
-
info "Codex router directives: begin the message with one space, e.g. ' /force-model gpt-5.6-terra'."
|
|
4490
4700
|
|
|
4491
4701
|
# Project scope: ensure the per-teammate config (which holds the router key)
|
|
4492
4702
|
# is gitignored. The base URL is the same for every teammate, so a
|
|
@@ -4535,7 +4745,9 @@ if [ "$target" = "opencode" ]; then
|
|
|
4535
4745
|
refuse_if_symlink "$gitignore"
|
|
4536
4746
|
for entry in \
|
|
4537
4747
|
"opencode.json" \
|
|
4538
|
-
".weave/"
|
|
4748
|
+
".weave/" \
|
|
4749
|
+
".weave-parked.json" \
|
|
4750
|
+
".opencode/commands/*.weave-router"
|
|
4539
4751
|
do
|
|
4540
4752
|
if [ ! -f "$gitignore" ] || ! grep -qxF "$entry" "$gitignore"; then
|
|
4541
4753
|
printf '%s\n' "$entry" >>"$gitignore"
|
|
@@ -4552,11 +4764,9 @@ if [ "$target" = "opencode" ]; then
|
|
|
4552
4764
|
#
|
|
4553
4765
|
# Router on/off/status are not installed — they run npx shell commands
|
|
4554
4766
|
# specific to the Claude Code settings model and don't apply to opencode.
|
|
4555
|
-
if [ "$scope" = "project" ]; then
|
|
4767
|
+
if [ "$scope" = "project" ] || [ -n "$install_dir" ]; then
|
|
4556
4768
|
opencode_commands_dir="$opencode_dir/.opencode/commands"
|
|
4557
4769
|
else
|
|
4558
|
-
# User scope and --dir installs: use the global commands path that opencode
|
|
4559
|
-
# discovers regardless of working directory.
|
|
4560
4770
|
opencode_commands_dir="${XDG_CONFIG_HOME:-$HOME/.config}/opencode/commands"
|
|
4561
4771
|
fi
|
|
4562
4772
|
install_slash_commands "$opencode_commands_dir"
|
|
@@ -4574,12 +4784,12 @@ if [ "$target" = "opencode" ]; then
|
|
|
4574
4784
|
# can outlive a plugin-less re-install that stripped the provider, which would
|
|
4575
4785
|
# make these instructions misleading.
|
|
4576
4786
|
if jq -e '(.provider // {}) | has("weave-claude")' "$opencode_config_file" >/dev/null 2>&1; then
|
|
4577
|
-
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${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."
|
|
4787
|
+
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."
|
|
4578
4788
|
fi
|
|
4579
4789
|
if [ -n "$install_dir" ]; then
|
|
4580
4790
|
# --dir installs land outside opencode's discovery roots, so the caller
|
|
4581
4791
|
# has to point opencode at the file explicitly.
|
|
4582
|
-
info "Run opencode with OPENCODE_CONFIG=$opencode_config_file opencode."
|
|
4792
|
+
info "Run opencode with OPENCODE_CONFIG=$opencode_config_file OPENCODE_CONFIG_DIR=$opencode_dir/.opencode opencode."
|
|
4583
4793
|
fi
|
|
4584
4794
|
[ "$mode" = "update" ] || print_uninstall_hint
|
|
4585
4795
|
exit 0
|
|
@@ -4642,6 +4852,7 @@ fi
|
|
|
4642
4852
|
|
|
4643
4853
|
# ---------- write the statusline script ----------
|
|
4644
4854
|
|
|
4855
|
+
if [ "$statusline_install" = "true" ]; then
|
|
4645
4856
|
cat > "$statusline_file" << 'STATUSLINE_EOF'
|
|
4646
4857
|
#!/usr/bin/env bash
|
|
4647
4858
|
#
|
|
@@ -4926,8 +5137,13 @@ weave_sync_commands() {
|
|
|
4926
5137
|
installed_body="$(sed '/^<!-- weave-router managed command: .* -->$/d' "$installed" 2>/dev/null)" || installed_body=""
|
|
4927
5138
|
if [ "$prev_body" = "$installed_body" ] && [ "$new_body" != "$installed_body" ]; then
|
|
4928
5139
|
tmp="$installed.tmp.$$"
|
|
4929
|
-
if printf '%s\n
|
|
5140
|
+
if printf '%s\n' "$new_body" >"$tmp" 2>/dev/null; then
|
|
4930
5141
|
mv "$tmp" "$installed" 2>/dev/null || rm -f "$tmp"
|
|
5142
|
+
ownership_file="$installed.weave-router"
|
|
5143
|
+
if [ ! -L "$ownership_file" ]; then
|
|
5144
|
+
printf 'weave-router managed command: %s\n%s\n' "$name" "$new_body" \
|
|
5145
|
+
>"$ownership_file" 2>/dev/null || true
|
|
5146
|
+
fi
|
|
4931
5147
|
else
|
|
4932
5148
|
rm -f "$tmp"
|
|
4933
5149
|
fi
|
|
@@ -5603,7 +5819,10 @@ else
|
|
|
5603
5819
|
fi
|
|
5604
5820
|
STATUSLINE_EOF
|
|
5605
5821
|
chmod +x "$statusline_file"
|
|
5822
|
+
printf '%s\n' "$CLAUDE_STATUSLINE_MARKER" >"$statusline_ownership_file"
|
|
5823
|
+
chmod 600 "$statusline_ownership_file"
|
|
5606
5824
|
ok "Statusline installed at $statusline_file"
|
|
5825
|
+
fi
|
|
5607
5826
|
|
|
5608
5827
|
# ---------- patch settings.json ----------
|
|
5609
5828
|
|
|
@@ -5623,6 +5842,7 @@ trap '_spin_cleanup; rm -f "$tmp_patch"' EXIT INT TERM HUP
|
|
|
5623
5842
|
# replacement key without re-running the whole install.
|
|
5624
5843
|
write_claude_settings() {
|
|
5625
5844
|
local block_key="$1"
|
|
5845
|
+
prepare_claude_context_window
|
|
5626
5846
|
|
|
5627
5847
|
# Claude Code splits ANTHROPIC_CUSTOM_HEADERS on newlines, so multiple headers
|
|
5628
5848
|
# ride in the same env var separated by \n. Append identity headers alongside
|
|
@@ -5642,26 +5862,26 @@ write_claude_settings() {
|
|
|
5642
5862
|
# Force tool-search deferral to match first-party Claude Code; "auto" can inline
|
|
5643
5863
|
# every tool schema when the custom endpoint advertises a 200K context window.
|
|
5644
5864
|
if [ "$scope" = "project" ] && [ -z "$install_dir" ]; then
|
|
5645
|
-
jq -n --arg url "$base_url" --arg sl "$statusline_path_for_settings" '{
|
|
5865
|
+
jq -n --arg url "$base_url" --arg sl "$statusline_path_for_settings" --arg statusline_install "$statusline_install" '{
|
|
5646
5866
|
env: { ANTHROPIC_BASE_URL: $url, ENABLE_TOOL_SEARCH: "true" },
|
|
5647
|
-
statusLine: { type: "command", command: $sl },
|
|
5648
5867
|
attribution: {
|
|
5649
5868
|
commit: "Co-Authored-By: Weave Router <router@workweave.ai>",
|
|
5650
5869
|
pr: "🤖 Generated with [Weave Router](https://router.workweave.ai)"
|
|
5651
5870
|
}
|
|
5652
|
-
}' >"$tmp_patch"
|
|
5871
|
+
} + (if $statusline_install == "true" then {statusLine: { type: "command", command: $sl }} else {} end)' >"$tmp_patch"
|
|
5653
5872
|
else
|
|
5654
|
-
jq -n --arg url "$base_url" --arg header "$custom_headers" --arg sl "$statusline_path_for_settings" '{
|
|
5873
|
+
jq -n --arg url "$base_url" --arg header "$custom_headers" --arg sl "$statusline_path_for_settings" --arg statusline_install "$statusline_install" '{
|
|
5655
5874
|
env: { ANTHROPIC_BASE_URL: $url, ANTHROPIC_CUSTOM_HEADERS: $header, ENABLE_TOOL_SEARCH: "true" },
|
|
5656
|
-
statusLine: { type: "command", command: $sl },
|
|
5657
5875
|
attribution: {
|
|
5658
5876
|
commit: "Co-Authored-By: Weave Router <router@workweave.ai>",
|
|
5659
5877
|
pr: "🤖 Generated with [Weave Router](https://router.workweave.ai)"
|
|
5660
5878
|
}
|
|
5661
|
-
}' >"$tmp_patch"
|
|
5879
|
+
} + (if $statusline_install == "true" then {statusLine: { type: "command", command: $sl }} else {} end)' >"$tmp_patch"
|
|
5662
5880
|
fi
|
|
5663
5881
|
|
|
5664
|
-
# Merge with existing settings. Deep-merge env and replace statusLine
|
|
5882
|
+
# Merge with existing settings. Deep-merge env and replace statusLine only
|
|
5883
|
+
# when this install owns the statusline slot; otherwise the patch omits it so
|
|
5884
|
+
# the user's existing statusline survives unchanged.
|
|
5665
5885
|
# We strip router-owned auth from the existing settings BEFORE merging —
|
|
5666
5886
|
# otherwise switching auth mode (key→dev-mode) would leave stale credentials
|
|
5667
5887
|
# behind. ANTHROPIC_AUTH_TOKEN/apiKeyHelper are also removed to migrate older
|
|
@@ -5705,6 +5925,7 @@ write_claude_settings() {
|
|
|
5705
5925
|
chmod 600 "$local_settings_file"
|
|
5706
5926
|
ok "Router key header written to $local_settings_file"
|
|
5707
5927
|
fi
|
|
5928
|
+
apply_claude_context_window install "$context_settings_file"
|
|
5708
5929
|
}
|
|
5709
5930
|
|
|
5710
5931
|
# write_claude_settings rewrites the full router config live, so a parked
|
|
@@ -5730,13 +5951,17 @@ if [ "$scope" = "project" ] && [ -z "$install_dir" ] && [ -n "${git_root:-}" ];
|
|
|
5730
5951
|
# Same symlink containment as the .claude/ paths above: a hostile repo could
|
|
5731
5952
|
# commit .gitignore as a symlink so the >> below writes outside the repo.
|
|
5732
5953
|
refuse_if_symlink "$gitignore"
|
|
5733
|
-
# Keep the statusline script and per-teammate local
|
|
5734
|
-
# local settings carry the router key header; each
|
|
5954
|
+
# Keep the router statusline script (when installed) and per-teammate local
|
|
5955
|
+
# settings out of git. The local settings carry the router key header; each
|
|
5956
|
+
# teammate gets their own.
|
|
5735
5957
|
for entry in \
|
|
5736
5958
|
".claude/settings.local.json" \
|
|
5737
5959
|
".claude/.credentials.json" \
|
|
5738
|
-
".claude/cc-statusline.sh"
|
|
5960
|
+
".claude/cc-statusline.sh" \
|
|
5961
|
+
".claude/cc-statusline.sh.weave-router" \
|
|
5962
|
+
".claude/commands/*.weave-router"
|
|
5739
5963
|
do
|
|
5964
|
+
[[ "$entry" == .claude/cc-statusline.sh* ]] && [ "$statusline_install" != "true" ] && continue
|
|
5740
5965
|
if [ ! -f "$gitignore" ] || ! grep -qxF "$entry" "$gitignore"; then
|
|
5741
5966
|
printf '%s\n' "$entry" >>"$gitignore"
|
|
5742
5967
|
fi
|