@weave-os/router 0.2.27 → 0.2.29
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 +1 -1
- package/cc-statusline.sh +66 -134
- package/codex-status.sh +1 -0
- package/codex-toggle.sh +1 -0
- package/install.sh +143 -163
- package/package.json +1 -1
- package/pi-router/src/pricing.generated.ts +4 -3
- package/uninstall.sh +1 -0
package/README.md
CHANGED
|
@@ -157,7 +157,7 @@ dependencies are separately licensed and are not bundled in this package.
|
|
|
157
157
|
|
|
158
158
|
- Node ≥ 18 (ships with `npx`)
|
|
159
159
|
- `bash` on PATH (macOS / Linux native; Windows needs Git Bash or WSL)
|
|
160
|
-
- `jq` on
|
|
160
|
+
- `jq` is reused when available; otherwise, on macOS (arm64/x86_64), Linux (arm64/x86_64), and Windows Git Bash (x86_64), the installer downloads checksum-verified jq 1.8.1 to `~/.weave/bin`. Other architectures need jq installed manually. No Homebrew or administrator access is needed. Downloads require access to GitHub.
|
|
161
161
|
|
|
162
162
|
## Why npx
|
|
163
163
|
|
package/cc-statusline.sh
CHANGED
|
@@ -1,26 +1,23 @@
|
|
|
1
1
|
#!/usr/bin/env bash
|
|
2
2
|
#
|
|
3
3
|
# Claude Code statusline for the Weave Router. CC pipes a JSON blob on stdin
|
|
4
|
-
# whose `transcript_path` points at the JSONL log
|
|
5
|
-
#
|
|
6
|
-
#
|
|
7
|
-
#
|
|
8
|
-
# stream and CC stores that in the transcript verbatim. Per-turn savings
|
|
9
|
-
# come from comparing each turn's routed cost against what the user's
|
|
10
|
-
# selection would have cost on the same tokens. Works identically for
|
|
11
|
-
# local docker and the managed cloud router — no sidecar, no DB, no auth.
|
|
4
|
+
# whose `transcript_path` points at the current session's JSONL log. Model
|
|
5
|
+
# names and price comparisons come from that local transcript; neither
|
|
6
|
+
# establishes the request's destination, including when the transcript
|
|
7
|
+
# contains an old router pin acknowledgement.
|
|
12
8
|
#
|
|
13
9
|
# Wire up by adding to ~/.claude/settings.json:
|
|
14
10
|
# { "statusLine": { "type": "command", "command": "/abs/path/to/cc-statusline.sh" } }
|
|
15
11
|
#
|
|
16
12
|
# Renders:
|
|
17
|
-
# WEAVE ROUTER
|
|
13
|
+
# WEAVE ROUTER · response model: claude-sonnet-4-5 · selected: claude-opus-4-7 · est. cost difference $1.23
|
|
18
14
|
#
|
|
19
15
|
# Pricing source of truth: internal/router/catalog. Input/output prices and
|
|
20
16
|
# cache-read multipliers are generated by cmd/genprices. Cache creation remains
|
|
21
17
|
# at 1.25× input pending TTL-aware pricing.
|
|
22
18
|
|
|
23
19
|
set -euo pipefail
|
|
20
|
+
export PATH="$PATH:$HOME/.weave/bin"
|
|
24
21
|
|
|
25
22
|
# ---------- background self-refresh ----------
|
|
26
23
|
#
|
|
@@ -442,20 +439,17 @@ fi
|
|
|
442
439
|
|
|
443
440
|
input="$(cat)"
|
|
444
441
|
transcript_path="$(printf '%s' "$input" | jq -r '.transcript_path // empty')"
|
|
445
|
-
# Prefer model.id over display_name: pricing keys + the
|
|
442
|
+
# Prefer model.id over display_name: pricing keys + the response model id in
|
|
446
443
|
# the transcript are canonical ids (e.g. claude-opus-4-7), while display_name
|
|
447
444
|
# is a human label ("Opus 4.7 (1M context)") that won't hit the pricing table,
|
|
448
|
-
#
|
|
445
|
+
# preventing a price comparison. id passes through normalize_model cleanly.
|
|
449
446
|
selected_display="$(printf '%s' "$input" | jq -r '.model.id // .model.display_name // "?"')"
|
|
450
447
|
|
|
451
448
|
# Normalize a model id to a pricing-table key. CC + the decisions log carry
|
|
452
449
|
# two flavors of annotation we don't want in the lookup:
|
|
453
450
|
# * date suffix: claude-opus-4-7-20260101 → claude-opus-4-7
|
|
454
451
|
# * variant tag: claude-opus-4-7[1m] → claude-opus-4-7
|
|
455
|
-
#
|
|
456
|
-
# the "saved $X vs your selection" UX the base rate is the right comparison
|
|
457
|
-
# — we're measuring the model swap, not the context tier. Used below on the
|
|
458
|
-
# routed and requested model ids from the decisions log / transcript.
|
|
452
|
+
# This estimate compares base model prices, not context-tier surcharges.
|
|
459
453
|
normalize_model() {
|
|
460
454
|
printf '%s' "$1" | sed -E 's/\[[^]]*\]$//; s/-[0-9]{8}$//'
|
|
461
455
|
}
|
|
@@ -481,10 +475,10 @@ prices='{
|
|
|
481
475
|
"claude-sonnet-4-6": 0.003,
|
|
482
476
|
"claude-sonnet-5": 0.003,
|
|
483
477
|
"claude-sonnet-5-5": 0.002,
|
|
484
|
-
"deepseek/deepseek-v4-flash": 0.
|
|
478
|
+
"deepseek/deepseek-v4-flash": 0.00014,
|
|
485
479
|
"deepseek/deepseek-v4-pro": 0.00174,
|
|
486
480
|
"deepseek/deepseek-v4-pro-0813": 0.00174,
|
|
487
|
-
"deepseek/deepseek-v4.1-flash": 0.
|
|
481
|
+
"deepseek/deepseek-v4.1-flash": 0.0002,
|
|
488
482
|
"gemini-2.0-flash": 0.0001,
|
|
489
483
|
"gemini-2.0-flash-lite": 0.000075,
|
|
490
484
|
"gemini-2.5-flash": 0.0003,
|
|
@@ -525,6 +519,7 @@ prices='{
|
|
|
525
519
|
"gpt-6-astra": 0.01,
|
|
526
520
|
"gpt-6-luna": 0.0001,
|
|
527
521
|
"gpt-6-sol": 0.002,
|
|
522
|
+
"gpt-6.1-sol": 0.002,
|
|
528
523
|
"grok-4.5": 0.002,
|
|
529
524
|
"grok-4.6": 0.002,
|
|
530
525
|
"grok-4.7": 0.002,
|
|
@@ -571,10 +566,10 @@ prices='{
|
|
|
571
566
|
"claude-sonnet-4-6": 0.015,
|
|
572
567
|
"claude-sonnet-5": 0.015,
|
|
573
568
|
"claude-sonnet-5-5": 0.01,
|
|
574
|
-
"deepseek/deepseek-v4-flash": 0.
|
|
569
|
+
"deepseek/deepseek-v4-flash": 0.00028,
|
|
575
570
|
"deepseek/deepseek-v4-pro": 0.00348,
|
|
576
571
|
"deepseek/deepseek-v4-pro-0813": 0.00348,
|
|
577
|
-
"deepseek/deepseek-v4.1-flash": 0.
|
|
572
|
+
"deepseek/deepseek-v4.1-flash": 0.00099,
|
|
578
573
|
"gemini-2.0-flash": 0.0004,
|
|
579
574
|
"gemini-2.0-flash-lite": 0.0003,
|
|
580
575
|
"gemini-2.5-flash": 0.0012,
|
|
@@ -615,6 +610,7 @@ prices='{
|
|
|
615
610
|
"gpt-6-astra": 0.05,
|
|
616
611
|
"gpt-6-luna": 0.0005,
|
|
617
612
|
"gpt-6-sol": 0.01,
|
|
613
|
+
"gpt-6.1-sol": 0.01,
|
|
618
614
|
"grok-4.5": 0.006,
|
|
619
615
|
"grok-4.6": 0.006,
|
|
620
616
|
"grok-4.7": 0.006,
|
|
@@ -661,10 +657,10 @@ prices='{
|
|
|
661
657
|
"claude-sonnet-4-6": 0.1,
|
|
662
658
|
"claude-sonnet-5": 0.1,
|
|
663
659
|
"claude-sonnet-5-5": 0.1,
|
|
664
|
-
"deepseek/deepseek-v4-flash": 0.
|
|
660
|
+
"deepseek/deepseek-v4-flash": 0.1,
|
|
665
661
|
"deepseek/deepseek-v4-pro": 0.0862,
|
|
666
662
|
"deepseek/deepseek-v4-pro-0813": 0.0862,
|
|
667
|
-
"deepseek/deepseek-v4.1-flash": 0.
|
|
663
|
+
"deepseek/deepseek-v4.1-flash": 0.03,
|
|
668
664
|
"gemini-2.0-flash": 0.25,
|
|
669
665
|
"gemini-2.0-flash-lite": 0.25,
|
|
670
666
|
"gemini-2.5-flash": 0.1,
|
|
@@ -705,6 +701,7 @@ prices='{
|
|
|
705
701
|
"gpt-6-astra": 0.1,
|
|
706
702
|
"gpt-6-luna": 0.1,
|
|
707
703
|
"gpt-6-sol": 0.1,
|
|
704
|
+
"gpt-6.1-sol": 0.05,
|
|
708
705
|
"grok-4.5": 0.25,
|
|
709
706
|
"grok-4.6": 0.25,
|
|
710
707
|
"grok-4.7": 0.25,
|
|
@@ -738,24 +735,14 @@ prices='{
|
|
|
738
735
|
}'
|
|
739
736
|
# END_GENERATED_PRICES
|
|
740
737
|
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
# Per-turn savings compare each turn's routed cost (priced from
|
|
751
|
-
# message.model in the transcript) against what the CC-side model selection
|
|
752
|
-
# (selected_display) would have cost on the same tokens. The selection
|
|
753
|
-
# isn't strictly the per-turn "requested" model — CC tags some background
|
|
754
|
-
# side-calls (compaction probes, title-gen) with a different model id —
|
|
755
|
-
# but for those the planner short-circuits to a hard pin and the savings
|
|
756
|
-
# math zeroes out anyway. Turns where routed == selection or where either
|
|
757
|
-
# model isn't in the pricing table emit 0 savings; the tokens clause
|
|
758
|
-
# always renders.
|
|
738
|
+
transcript_model=""
|
|
739
|
+
has_pin_record="false"
|
|
740
|
+
last_pin_model=""
|
|
741
|
+
session_cost_difference=""
|
|
742
|
+
|
|
743
|
+
# This is a hypothetical comparison against the CURRENT selection, not
|
|
744
|
+
# realized router savings: the transcript does not record each turn's
|
|
745
|
+
# requested model or prove that any turn went through the router.
|
|
759
746
|
|
|
760
747
|
# Normalize the CC-side selection once for use in the jq math below.
|
|
761
748
|
requested_norm="$(normalize_model "$selected_display")"
|
|
@@ -769,16 +756,16 @@ if [[ -n "$transcript_path" && -f "$transcript_path" ]]; then
|
|
|
769
756
|
# locally (errored requests, cancellations, tool-only stubs) instead of a
|
|
770
757
|
# real model id. Show that as "failure" rather than leaking the internal
|
|
771
758
|
# sentinel into the statusline.
|
|
772
|
-
|
|
759
|
+
transcript_model="$("${reverse[@]}" "$transcript_path" 2>/dev/null \
|
|
773
760
|
| jq -r 'select(.type=="assistant") | .message.model // empty' \
|
|
774
761
|
| head -n 1 || true)"
|
|
775
|
-
if [[ "$
|
|
776
|
-
|
|
762
|
+
if [[ "$transcript_model" == "<synthetic>" ]]; then
|
|
763
|
+
transcript_model="failure"
|
|
777
764
|
else
|
|
778
|
-
|
|
765
|
+
transcript_model="$(normalize_model "$transcript_model")"
|
|
779
766
|
fi
|
|
780
767
|
|
|
781
|
-
#
|
|
768
|
+
# Read the last /force-model acknowledgement in the transcript —
|
|
782
769
|
# the only turns stamped message.model == "weave-router". The router emits
|
|
783
770
|
# one whenever a pin changes state:
|
|
784
771
|
# * /force-model → "force-model applied: <model> (<provider>) …"
|
|
@@ -797,8 +784,8 @@ if [[ -n "$transcript_path" && -f "$transcript_path" ]]; then
|
|
|
797
784
|
# These persist on disk (the ingress stripper only scrubs them from upstream
|
|
798
785
|
# requests). Classify each weave-router turn newest-first, skip the no-op
|
|
799
786
|
# "rejected" acks, and let the latest real state change decide: an "applied"
|
|
800
|
-
# marker
|
|
801
|
-
#
|
|
787
|
+
# marker records a pin (and names the model); a later clear removes it.
|
|
788
|
+
# This history cannot establish the running client's route or current pin.
|
|
802
789
|
# Restricting to weave-router turns keeps a normal reply that merely quotes
|
|
803
790
|
# these phrases from flipping the tag. (A silent server-side TTL expiry emits
|
|
804
791
|
# no turn and so can't be reflected here — the pin TTL outlives a session.)
|
|
@@ -811,20 +798,11 @@ if [[ -n "$transcript_path" && -f "$transcript_path" ]]; then
|
|
|
811
798
|
else "CLEARED" end' 2>/dev/null \
|
|
812
799
|
| grep -m1 -v '^REJECTED$' || true)"
|
|
813
800
|
if [[ "$force_state" == APPLIED\ * ]]; then
|
|
814
|
-
|
|
815
|
-
|
|
801
|
+
has_pin_record="true"
|
|
802
|
+
last_pin_model="${force_state#APPLIED }"
|
|
816
803
|
fi
|
|
817
804
|
|
|
818
|
-
#
|
|
819
|
-
# whose marker reports a requested ≠ routed swap, plus cumulative token
|
|
820
|
-
# counts across every assistant turn (rerouted or not — total work the
|
|
821
|
-
# session has done). cache_creation is priced at 1.25× input; cache_read
|
|
822
|
-
# uses each model's generated catalog multiplier. Both are no-ops when the
|
|
823
|
-
# provider does not return those fields.
|
|
824
|
-
#
|
|
825
|
-
# The marker regex tolerates the optional "(<provider>)" segment and a
|
|
826
|
-
# `[1m]` / `-YYYYMMDD` suffix on either model name so transcripts written
|
|
827
|
-
# against context-tiered or dated model ids still parse cleanly.
|
|
805
|
+
# Missing prices leave the comparison unknown without hiding the model.
|
|
828
806
|
#
|
|
829
807
|
# Dedup note: CC writes one JSONL entry per *content block* in an
|
|
830
808
|
# assistant turn (text, text, tool_use → 3 entries), and every entry
|
|
@@ -838,9 +816,9 @@ if [[ -n "$transcript_path" && -f "$transcript_path" ]]; then
|
|
|
838
816
|
# grows), so the composite key keeps turns distinct. Two turns with
|
|
839
817
|
# byte-identical id AND usage would still collapse, but that's a
|
|
840
818
|
# genuine retry/duplicate we want to drop.
|
|
841
|
-
|
|
819
|
+
session_cost_difference="$(
|
|
842
820
|
jq -rs --argjson p "$prices" --arg requested "$requested_norm" '
|
|
843
|
-
[.[] | select(.type=="assistant")] |
|
|
821
|
+
[.[] | select(.type=="assistant" and .message.model!="<synthetic>" and .message.model!="weave-router")] |
|
|
844
822
|
unique_by([.message.id, .message.usage]) |
|
|
845
823
|
.[] |
|
|
846
824
|
.message as $m |
|
|
@@ -851,13 +829,13 @@ if [[ -n "$transcript_path" && -f "$transcript_path" ]]; then
|
|
|
851
829
|
cwrt: ($m.usage.cache_creation_input_tokens // 0),
|
|
852
830
|
crd: ($m.usage.cache_read_input_tokens // 0)
|
|
853
831
|
} as $t |
|
|
854
|
-
(if $
|
|
832
|
+
(if ($t.in + $t.out + $t.cwrt + $t.crd) == 0 then 0
|
|
855
833
|
else
|
|
856
834
|
($p.input[$rm] // null) as $rin | ($p.output[$rm] // null) as $rout |
|
|
857
835
|
($p.cache_read[$rm] // null) as $rcr |
|
|
858
836
|
($p.input[$requested] // null) as $sin | ($p.output[$requested] // null) as $sout |
|
|
859
837
|
($p.cache_read[$requested] // null) as $scr |
|
|
860
|
-
if ($rin == null or $rout == null or $rcr == null or $sin == null or $sout == null or $scr == null) then
|
|
838
|
+
if ($rin == null or $rout == null or $rcr == null or $sin == null or $sout == null or $scr == null) then null
|
|
861
839
|
else
|
|
862
840
|
(($t.in + 1.25 * $t.cwrt + $rcr * $t.crd) / 1000) as $routed_input_units |
|
|
863
841
|
(($t.in + 1.25 * $t.cwrt + $scr * $t.crd) / 1000) as $requested_input_units |
|
|
@@ -867,21 +845,20 @@ if [[ -n "$transcript_path" && -f "$transcript_path" ]]; then
|
|
|
867
845
|
($requested_cost - $routed_cost)
|
|
868
846
|
end
|
|
869
847
|
end) as $savings |
|
|
870
|
-
|
|
848
|
+
if $savings == null then "unknown" else $savings end
|
|
871
849
|
' "$transcript_path" 2>/dev/null \
|
|
872
|
-
| awk 'BEGIN{s=0
|
|
873
|
-
{
|
|
874
|
-
END{
|
|
875
|
-
|
|
850
|
+
| awk 'BEGIN{s=0}
|
|
851
|
+
{if ($1 == "unknown") comparison_unknown=1; else s+=$1}
|
|
852
|
+
END{
|
|
853
|
+
if (NR == 0 || comparison_unknown) printf "unknown"; else printf "%.4f", s;
|
|
854
|
+
}'
|
|
855
|
+
)" || true
|
|
876
856
|
fi
|
|
877
857
|
|
|
878
858
|
# ---------- refresh when a model isn't in the pricing table ----------
|
|
879
859
|
#
|
|
880
|
-
# A model
|
|
881
|
-
#
|
|
882
|
-
# — indistinguishable from "the router ran and didn't beat your selection". The
|
|
883
|
-
# periodic check heals that eventually, but a week late, and a model launch is
|
|
884
|
-
# exactly when the number gets looked at. Refresh off-schedule instead.
|
|
860
|
+
# A model missing from this copy's price table cannot be compared. Refresh
|
|
861
|
+
# off-schedule instead of waiting up to a week for the periodic check.
|
|
885
862
|
#
|
|
886
863
|
# Keyed on its own stamp per unpriced id: a model we never price (self-hosted,
|
|
887
864
|
# unrecognized) then costs one download per interval, not one per turn, and
|
|
@@ -909,7 +886,7 @@ weave_refresh_on_price_miss() {
|
|
|
909
886
|
model_slug="$(printf '%s' "$missing" | tr -c 'A-Za-z0-9._-' '_')"
|
|
910
887
|
weave_self_refresh ".miss.${model_slug}" 1
|
|
911
888
|
}
|
|
912
|
-
weave_refresh_on_price_miss "$requested_norm" "$
|
|
889
|
+
weave_refresh_on_price_miss "$requested_norm" "$transcript_model" 2>/dev/null || true
|
|
913
890
|
|
|
914
891
|
# Brand color (#FF6C47) on terminals that grok 24-bit truecolor — that's
|
|
915
892
|
# every modern one (iTerm2, Apple Terminal, vscode, ghostty, alacritty,
|
|
@@ -920,71 +897,26 @@ brand=$'\033[38;2;255;108;71mWEAVE ROUTER\033[0m'
|
|
|
920
897
|
fmt_money() {
|
|
921
898
|
awk -v v="$1" 'BEGIN{
|
|
922
899
|
if (v == "" || v+0 == 0) { printf "$0.00"; exit }
|
|
923
|
-
if (v+0 < 0.005 && v+0 > -0.005){ printf "<$0.01";
|
|
900
|
+
if (v+0 < 0.005 && v+0 > -0.005){ printf "%s<$0.01", (v+0 < 0 ? "-" : ""); exit }
|
|
924
901
|
if (v+0 < 0) { printf "-$%.2f", -v+0; exit }
|
|
925
902
|
printf "$%.2f", v
|
|
926
903
|
}'
|
|
927
904
|
}
|
|
928
905
|
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
}
|
|
937
|
-
|
|
938
|
-
# cache_read tokens are the cached portion of every prompt that the
|
|
939
|
-
# provider serves at 0.1× input price; cache_write tokens are the bytes
|
|
940
|
-
# that get newly cached on this turn at 1.25× input price. They behave
|
|
941
|
-
# completely differently both in cost and in what they tell the user
|
|
942
|
-
# about session-level efficiency, so we surface them separately rather
|
|
943
|
-
# than summing into a single "cached" number that conflates the two.
|
|
944
|
-
# Each clause is shown only when nonzero, so quiet sessions stay quiet.
|
|
945
|
-
tokens_clause=""
|
|
946
|
-
if [[ "$tot_in" -gt 0 || "$tot_out" -gt 0 || "$tot_cache_read" -gt 0 || "$tot_cache_write" -gt 0 ]]; then
|
|
947
|
-
tokens_clause=" · $(fmt_tok "$tot_in") in / $(fmt_tok "$tot_out") out"
|
|
948
|
-
if [[ "$tot_cache_read" -gt 0 ]]; then
|
|
949
|
-
tokens_clause+=" / $(fmt_tok "$tot_cache_read") cache read"
|
|
950
|
-
fi
|
|
951
|
-
if [[ "$tot_cache_write" -gt 0 ]]; then
|
|
952
|
-
tokens_clause+=" / $(fmt_tok "$tot_cache_write") cache write"
|
|
953
|
-
fi
|
|
906
|
+
printf '%s' "$brand"
|
|
907
|
+
if [[ "$transcript_model" == "failure" ]]; then
|
|
908
|
+
printf ' · last response failed'
|
|
909
|
+
elif [[ "$transcript_model" == "weave-router" ]]; then
|
|
910
|
+
printf ' · control acknowledgement'
|
|
911
|
+
elif [[ -n "$transcript_model" ]]; then
|
|
912
|
+
printf ' · response model: %s' "$transcript_model"
|
|
954
913
|
fi
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
printf '
|
|
963
|
-
elif [[ "$routed" == "failure" ]]; then
|
|
964
|
-
# Latest turn was a CC-synthesized error stub — don't claim a routing
|
|
965
|
-
# swap or compute savings against a non-model.
|
|
966
|
-
printf '%s — %s%s' "$brand" "$routed" "$tokens_clause"
|
|
967
|
-
elif [[ -n "$routed" ]]; then
|
|
968
|
-
# Always show the savings clause, flooring a non-positive total at $0.00.
|
|
969
|
-
# session_savings is "0.0000" on fresh sessions or sessions where every
|
|
970
|
-
# turn routed back to the selected model, and can go negative when routing
|
|
971
|
-
# upgrades a turn to a pricier model (e.g. a sticky/hard-pinned side-call,
|
|
972
|
-
# or a hard turn escalated to opus). "saved -$X" would mislead, so clamp
|
|
973
|
-
# the display to $0.00 rather than dropping the clause — a $0.00 readout
|
|
974
|
-
# tells the user the router ran and simply didn't beat their selection.
|
|
975
|
-
# When the CC selection is unknown ("?" or empty) there's nothing to
|
|
976
|
-
# compare against, so drop the "← selection" arrow and just show routed.
|
|
977
|
-
display_savings="$session_savings"
|
|
978
|
-
if [[ -z "$display_savings" ]] \
|
|
979
|
-
|| awk -v v="$display_savings" 'BEGIN{exit !(v+0 < 0)}'; then
|
|
980
|
-
display_savings="0"
|
|
981
|
-
fi
|
|
982
|
-
if [[ -n "$selected_display" && "$selected_display" != "?" ]]; then
|
|
983
|
-
printf '%s — %s ← %s · saved %s%s' \
|
|
984
|
-
"$brand" "$routed" "$selected_display" "$(fmt_money "$display_savings")" "$tokens_clause"
|
|
985
|
-
else
|
|
986
|
-
printf '%s — %s%s' "$brand" "$routed" "$tokens_clause"
|
|
987
|
-
fi
|
|
988
|
-
else
|
|
989
|
-
printf '%s — %s%s' "$brand" "$selected_display" "$tokens_clause"
|
|
914
|
+
if [[ -n "$selected_display" && "$selected_display" != "?" ]]; then
|
|
915
|
+
printf ' · selected: %s' "$selected_display"
|
|
916
|
+
fi
|
|
917
|
+
if [[ -n "$session_cost_difference" && "$session_cost_difference" != "unknown" && "$transcript_model" != "failure" && "$transcript_model" != "weave-router" ]]; then
|
|
918
|
+
printf ' · est. cost difference %s' "$(fmt_money "$session_cost_difference")"
|
|
919
|
+
fi
|
|
920
|
+
if [[ "$has_pin_record" == "true" ]]; then
|
|
921
|
+
printf ' · last pin: %s' "$last_pin_model"
|
|
990
922
|
fi
|
package/codex-status.sh
CHANGED
package/codex-toggle.sh
CHANGED
package/install.sh
CHANGED
|
@@ -102,6 +102,7 @@
|
|
|
102
102
|
# it rather than editing.
|
|
103
103
|
|
|
104
104
|
set -euo pipefail
|
|
105
|
+
export PATH="$PATH:$HOME/.weave/bin"
|
|
105
106
|
|
|
106
107
|
# ---------- defaults ----------
|
|
107
108
|
|
|
@@ -263,6 +264,7 @@ SPIN_FRAMES='⠋ ⠙ ⠹ ⠸ ⠼ ⠴ ⠦ ⠧ ⠇ ⠏'
|
|
|
263
264
|
SPIN_INTERVAL=0.08
|
|
264
265
|
spin_pid=""
|
|
265
266
|
spin_log=""
|
|
267
|
+
jq_download_tmp=""
|
|
266
268
|
|
|
267
269
|
_spin_cleanup() {
|
|
268
270
|
# Kill any active spinner child and restore the cursor. Called from the
|
|
@@ -273,6 +275,10 @@ _spin_cleanup() {
|
|
|
273
275
|
wait "$spin_pid" 2>/dev/null || true
|
|
274
276
|
fi
|
|
275
277
|
spin_pid=""
|
|
278
|
+
if [ -n "$jq_download_tmp" ]; then
|
|
279
|
+
rm -f "$jq_download_tmp" 2>/dev/null || true
|
|
280
|
+
jq_download_tmp=""
|
|
281
|
+
fi
|
|
276
282
|
if [ "$tty_out" = "true" ]; then
|
|
277
283
|
printf '\033[?25h' # show cursor
|
|
278
284
|
fi
|
|
@@ -352,6 +358,47 @@ usage() {
|
|
|
352
358
|
exit "${1:-0}"
|
|
353
359
|
}
|
|
354
360
|
|
|
361
|
+
ensure_jq() {
|
|
362
|
+
command -v jq >/dev/null 2>&1 && return 0
|
|
363
|
+
local asset checksum destination temporary actual_checksum
|
|
364
|
+
case "$(uname -s):$(uname -m)" in
|
|
365
|
+
Darwin:arm64) asset=jq-macos-arm64; checksum=a9fe3ea2f86dfc72f6728417521ec9067b343277152b114f4e98d8cb0e263603 ;;
|
|
366
|
+
Darwin:x86_64) asset=jq-macos-amd64; checksum=e80dbe0d2a2597e3c11c404f03337b981d74b4a8504b70586c354b7697a7c27f ;;
|
|
367
|
+
Linux:x86_64) asset=jq-linux-amd64; checksum=020468de7539ce70ef1bceaf7cde2e8c4f2ca6c3afb84642aabc5c97d9fc2a0d ;;
|
|
368
|
+
Linux:aarch64|Linux:arm64) asset=jq-linux-arm64; checksum=6bc62f25981328edd3cfcfe6fe51b073f2d7e7710d7ef7fcdac28d4e384fc3d4 ;;
|
|
369
|
+
MINGW*:x86_64|MSYS*:x86_64|CYGWIN*:x86_64) asset=jq-windows-amd64.exe; checksum=23cb60a1354eed6bcc8d9b9735e8c7b388cd1fdcb75726b93bc299ef22dd9334 ;;
|
|
370
|
+
*) err "Automatic jq installation is unavailable for $(uname -s)/$(uname -m). Install jq and retry."; exit 1 ;;
|
|
371
|
+
esac
|
|
372
|
+
require_cmd curl "curl is required to download jq."
|
|
373
|
+
destination="$HOME/.weave/bin"
|
|
374
|
+
mkdir -p "$destination"
|
|
375
|
+
temporary="$(mktemp "$destination/.jq.XXXXXX")"
|
|
376
|
+
jq_download_tmp="$temporary"
|
|
377
|
+
info "Downloading jq 1.8.1 ($asset)."
|
|
378
|
+
if ! curl --fail --location --silent --show-error --connect-timeout 15 --max-time 120 \
|
|
379
|
+
"https://github.com/jqlang/jq/releases/download/jq-1.8.1/$asset" -o "$temporary"; then
|
|
380
|
+
err "Could not download jq. Check access to github.com or install jq and retry."
|
|
381
|
+
exit 1
|
|
382
|
+
fi
|
|
383
|
+
if command -v sha256sum >/dev/null 2>&1; then
|
|
384
|
+
actual_checksum="$(sha256sum "$temporary" | awk '{print $1}')"
|
|
385
|
+
else
|
|
386
|
+
require_cmd shasum "shasum or sha256sum is required to verify jq."
|
|
387
|
+
actual_checksum="$(shasum -a 256 "$temporary" | awk '{print $1}')"
|
|
388
|
+
fi
|
|
389
|
+
if [ "$actual_checksum" != "$checksum" ]; then
|
|
390
|
+
err "Downloaded jq failed checksum verification. Retry or install jq manually."
|
|
391
|
+
exit 1
|
|
392
|
+
fi
|
|
393
|
+
chmod 755 "$temporary"
|
|
394
|
+
case "$asset" in
|
|
395
|
+
*.exe) mv -f "$temporary" "$destination/jq.exe" ;;
|
|
396
|
+
*) mv -f "$temporary" "$destination/jq" ;;
|
|
397
|
+
esac
|
|
398
|
+
jq_download_tmp=""
|
|
399
|
+
jq --version >/dev/null
|
|
400
|
+
}
|
|
401
|
+
|
|
355
402
|
require_cmd() {
|
|
356
403
|
local cmd="$1" hint="$2"
|
|
357
404
|
if ! command -v "$cmd" >/dev/null 2>&1; then
|
|
@@ -1235,6 +1282,7 @@ write_pi_models_config() {
|
|
|
1235
1282
|
{ id: "claude-haiku-4-5", name: "Claude Haiku 4.5 (via Weave Router)", reasoning: true, input: ["text","image"], contextWindow: 200000, maxTokens: 32000 },
|
|
1236
1283
|
{ id: "gpt-6-astra", name: "GPT-6 Astra (via Weave Router)", reasoning: true, input: ["text","image"], contextWindow: 1050000, maxTokens: 128000 },
|
|
1237
1284
|
{ id: "gpt-6-sol", name: "GPT-6 Sol (via Weave Router)", reasoning: true, input: ["text","image"], contextWindow: 1050000, maxTokens: 128000 },
|
|
1285
|
+
{ id: "gpt-6.1-sol", name: "GPT-6.1 Sol (via Weave Router)", reasoning: true, input: ["text","image"], contextWindow: 1050000, maxTokens: 128000 },
|
|
1238
1286
|
{ id: "gpt-6-luna", name: "GPT-6 Luna (via Weave Router)", reasoning: true, input: ["text","image"], contextWindow: 1050000, maxTokens: 128000 },
|
|
1239
1287
|
{ id: "gpt-5.6-sol", name: "GPT-5.6 Sol (via Weave Router)", reasoning: true, input: ["text","image"], contextWindow: 1050000, maxTokens: 128000 },
|
|
1240
1288
|
{ id: "grok-4.5", name: "Grok 4.5 (via Weave Router)", reasoning: true, input: ["text","image"], contextWindow: 500000, maxTokens: 131072 },
|
|
@@ -1817,7 +1865,7 @@ fi
|
|
|
1817
1865
|
# found`. Installing Codex itself still needs no jq.
|
|
1818
1866
|
if [ "$target" = "claude" ] || [ "$target" = "opencode" ] || [ "$target" = "pi" ] \
|
|
1819
1867
|
|| { [ "$mode" = "models" ] && [ "$target" = "codex" ]; }; then
|
|
1820
|
-
|
|
1868
|
+
ensure_jq
|
|
1821
1869
|
fi
|
|
1822
1870
|
# curl is used by the install/update paths' health/validate probes and by every
|
|
1823
1871
|
# `models` call. The on/off toggles only ping the router best-effort after a
|
|
@@ -2683,33 +2731,29 @@ toggle_claude() {
|
|
|
2683
2731
|
case "$mode" in
|
|
2684
2732
|
status)
|
|
2685
2733
|
local on_hint="on --claude"
|
|
2686
|
-
|
|
2687
|
-
|
|
2688
|
-
|
|
2689
|
-
|
|
2690
|
-
|
|
2691
|
-
|
|
2692
|
-
ok "Claude Code (project): ${C_BOLD}off${C_RESET} — routing directly to Anthropic. Run '$on_hint' to re-enable."
|
|
2693
|
-
elif router_shaped_url "$committed_base"; then
|
|
2694
|
-
# Router URL is committed, but it only authenticates if this teammate's
|
|
2695
|
-
# settings.local.json carries the key header. A fresh clone (shared
|
|
2696
|
-
# settings.json, no personal local file) has the URL but no key.
|
|
2697
|
-
if claude_key_present "$local_settings_file"; then
|
|
2698
|
-
ok "Claude Code (project): ${C_BOLD}on${C_RESET} — routing through $committed_base."
|
|
2699
|
-
else
|
|
2700
|
-
warn "Claude Code (project): router URL is set but your personal router key is missing (no settings.local.json) — requests won't authenticate. Run the installer to add your key."
|
|
2701
|
-
fi
|
|
2702
|
-
else
|
|
2703
|
-
info "Claude Code (project): not configured for the router. Run the installer first."
|
|
2734
|
+
local effective_base="$committed_base" key_settings_file="$settings_file" status_label="Claude Code"
|
|
2735
|
+
[ "$scope" = "project" ] && on_hint="on --claude --scope project"
|
|
2736
|
+
if [ "$scope" = "project" ]; then
|
|
2737
|
+
status_label="Claude Code (project)"
|
|
2738
|
+
if [ -f "$local_settings_file" ] && jq -e '.env | has("ANTHROPIC_BASE_URL")' "$local_settings_file" >/dev/null 2>&1; then
|
|
2739
|
+
effective_base="$(json_get "$local_settings_file" '.env.ANTHROPIC_BASE_URL')"
|
|
2704
2740
|
fi
|
|
2705
|
-
|
|
2706
|
-
|
|
2707
|
-
|
|
2741
|
+
if [ -f "$local_settings_file" ] && jq -e '.env | has("ANTHROPIC_CUSTOM_HEADERS")' "$local_settings_file" >/dev/null 2>&1; then
|
|
2742
|
+
key_settings_file="$local_settings_file"
|
|
2743
|
+
fi
|
|
2744
|
+
fi
|
|
2745
|
+
if router_shaped_url "$effective_base"; then
|
|
2746
|
+
if claude_key_present "$key_settings_file"; then
|
|
2747
|
+
ok "$status_label: ${C_BOLD}on${C_RESET} in saved settings — endpoint $effective_base."
|
|
2708
2748
|
else
|
|
2709
|
-
warn "
|
|
2749
|
+
warn "$status_label: router key header is missing from active settings — Weave-key authentication is not configured; other authentication methods are not checked."
|
|
2710
2750
|
fi
|
|
2751
|
+
elif [ "$parked_present" = "true" ]; then
|
|
2752
|
+
ok "Claude Code: ${C_BOLD}off${C_RESET} in saved settings — direct to Anthropic. Run '$on_hint' to re-enable."
|
|
2753
|
+
elif [ -n "$effective_base" ]; then
|
|
2754
|
+
ok "$status_label: ${C_BOLD}off${C_RESET} in saved settings — direct to Anthropic. Run '$on_hint' to re-enable."
|
|
2711
2755
|
else
|
|
2712
|
-
info "
|
|
2756
|
+
info "$status_label: not configured for the router in this scope."
|
|
2713
2757
|
fi
|
|
2714
2758
|
;;
|
|
2715
2759
|
off)
|
|
@@ -3557,7 +3601,7 @@ run_login() {
|
|
|
3557
3601
|
extra="$(printf '%s\n' "$models_args" | tail -n +2)"
|
|
3558
3602
|
[ -n "$provider" ] || { err "Use 'login claude' or 'login codex'."; exit 2; }
|
|
3559
3603
|
[ -z "$extra" ] || { err "Login accepts exactly one provider."; exit 2; }
|
|
3560
|
-
|
|
3604
|
+
ensure_jq
|
|
3561
3605
|
require_cmd openssl "Install OpenSSL to enroll a subscription account."
|
|
3562
3606
|
case "$provider" in
|
|
3563
3607
|
claude) run_login_claude ;;
|
|
@@ -3567,7 +3611,7 @@ run_login() {
|
|
|
3567
3611
|
}
|
|
3568
3612
|
|
|
3569
3613
|
run_router_status() {
|
|
3570
|
-
local saved_target
|
|
3614
|
+
local saved_target codex_endpoint redacted_key
|
|
3571
3615
|
saved_target="$target"
|
|
3572
3616
|
settings_dir="$settings_base/.claude"
|
|
3573
3617
|
settings_file="$settings_dir/settings.json"
|
|
@@ -3577,7 +3621,6 @@ run_router_status() {
|
|
|
3577
3621
|
local_settings_file=""
|
|
3578
3622
|
fi
|
|
3579
3623
|
codex_config_file="$settings_base/.codex/config.toml"
|
|
3580
|
-
target="claude"; claude_endpoint="$(resolve_installed_endpoint)"
|
|
3581
3624
|
target="codex"; codex_endpoint="$(resolve_installed_endpoint)"
|
|
3582
3625
|
target="$saved_target"
|
|
3583
3626
|
if [ "${#api_key}" -gt 8 ]; then
|
|
@@ -3587,11 +3630,14 @@ run_router_status() {
|
|
|
3587
3630
|
fi
|
|
3588
3631
|
printf 'Router: %s\nIdentity: %s\n' "$base_url" "$redacted_key"
|
|
3589
3632
|
if models_api GET "/validate"; then
|
|
3590
|
-
printf 'Connectivity: connected\n'
|
|
3633
|
+
printf 'Connectivity: connected (API key accepted; inference not verified)\n'
|
|
3591
3634
|
else
|
|
3592
3635
|
printf 'Connectivity: unavailable (HTTP %s)\n' "${models_http_status:-network error}"
|
|
3593
3636
|
fi
|
|
3594
|
-
printf 'Claude Code: %s
|
|
3637
|
+
printf 'Claude Code settings: %s (scope: %s)\n' "$settings_dir" "$scope"
|
|
3638
|
+
# Administrative lookup includes parked credentials; routing status must not.
|
|
3639
|
+
toggle_claude
|
|
3640
|
+
printf 'Status describes this scope only, not a running session; other scopes or runtime overrides may differ. Restart Claude Code after on/off changes.\n'
|
|
3595
3641
|
printf 'Codex: %s\n' "$(if [ "${codex_endpoint%/}" = "${base_url%/}" ]; then printf 'points at Router'; elif [ -n "$codex_endpoint" ]; then printf 'different endpoint (%s)' "$codex_endpoint"; else printf 'not configured'; fi)"
|
|
3596
3642
|
if models_api GET "/v1/subscriptions/accounts"; then
|
|
3597
3643
|
printf 'Subscription accounts:\n'
|
|
@@ -4318,6 +4364,7 @@ install_codex_status_script() {
|
|
|
4318
4364
|
# blocks on the network, and every failure path leaves the title model-only.
|
|
4319
4365
|
|
|
4320
4366
|
set -euo pipefail
|
|
4367
|
+
export PATH="$PATH:$HOME/.weave/bin"
|
|
4321
4368
|
|
|
4322
4369
|
# ---------- background self-refresh ----------
|
|
4323
4370
|
#
|
|
@@ -4801,6 +4848,7 @@ install_codex_directive_script() {
|
|
|
4801
4848
|
# fire.
|
|
4802
4849
|
|
|
4803
4850
|
set -uo pipefail
|
|
4851
|
+
export PATH="$PATH:$HOME/.weave/bin"
|
|
4804
4852
|
|
|
4805
4853
|
# How long the toggle may take before the hook gives up and passes the prompt
|
|
4806
4854
|
# through. npx resolves from cache after first use; the budget covers a cold
|
|
@@ -5186,26 +5234,23 @@ cat > "$statusline_file" << 'STATUSLINE_EOF'
|
|
|
5186
5234
|
#!/usr/bin/env bash
|
|
5187
5235
|
#
|
|
5188
5236
|
# Claude Code statusline for the Weave Router. CC pipes a JSON blob on stdin
|
|
5189
|
-
# whose `transcript_path` points at the JSONL log
|
|
5190
|
-
#
|
|
5191
|
-
#
|
|
5192
|
-
#
|
|
5193
|
-
# stream and CC stores that in the transcript verbatim. Per-turn savings
|
|
5194
|
-
# come from comparing each turn's routed cost against what the user's
|
|
5195
|
-
# selection would have cost on the same tokens. Works identically for
|
|
5196
|
-
# local docker and the managed cloud router — no sidecar, no DB, no auth.
|
|
5237
|
+
# whose `transcript_path` points at the current session's JSONL log. Model
|
|
5238
|
+
# names and price comparisons come from that local transcript; neither
|
|
5239
|
+
# establishes the request's destination, including when the transcript
|
|
5240
|
+
# contains an old router pin acknowledgement.
|
|
5197
5241
|
#
|
|
5198
5242
|
# Wire up by adding to ~/.claude/settings.json:
|
|
5199
5243
|
# { "statusLine": { "type": "command", "command": "/abs/path/to/cc-statusline.sh" } }
|
|
5200
5244
|
#
|
|
5201
5245
|
# Renders:
|
|
5202
|
-
# WEAVE ROUTER
|
|
5246
|
+
# WEAVE ROUTER · response model: claude-sonnet-4-5 · selected: claude-opus-4-7 · est. cost difference $1.23
|
|
5203
5247
|
#
|
|
5204
5248
|
# Pricing source of truth: internal/router/catalog. Input/output prices and
|
|
5205
5249
|
# cache-read multipliers are generated by cmd/genprices. Cache creation remains
|
|
5206
5250
|
# at 1.25× input pending TTL-aware pricing.
|
|
5207
5251
|
|
|
5208
5252
|
set -euo pipefail
|
|
5253
|
+
export PATH="$PATH:$HOME/.weave/bin"
|
|
5209
5254
|
|
|
5210
5255
|
# ---------- background self-refresh ----------
|
|
5211
5256
|
#
|
|
@@ -5627,20 +5672,17 @@ fi
|
|
|
5627
5672
|
|
|
5628
5673
|
input="$(cat)"
|
|
5629
5674
|
transcript_path="$(printf '%s' "$input" | jq -r '.transcript_path // empty')"
|
|
5630
|
-
# Prefer model.id over display_name: pricing keys + the
|
|
5675
|
+
# Prefer model.id over display_name: pricing keys + the response model id in
|
|
5631
5676
|
# the transcript are canonical ids (e.g. claude-opus-4-7), while display_name
|
|
5632
5677
|
# is a human label ("Opus 4.7 (1M context)") that won't hit the pricing table,
|
|
5633
|
-
#
|
|
5678
|
+
# preventing a price comparison. id passes through normalize_model cleanly.
|
|
5634
5679
|
selected_display="$(printf '%s' "$input" | jq -r '.model.id // .model.display_name // "?"')"
|
|
5635
5680
|
|
|
5636
5681
|
# Normalize a model id to a pricing-table key. CC + the decisions log carry
|
|
5637
5682
|
# two flavors of annotation we don't want in the lookup:
|
|
5638
5683
|
# * date suffix: claude-opus-4-7-20260101 → claude-opus-4-7
|
|
5639
5684
|
# * variant tag: claude-opus-4-7[1m] → claude-opus-4-7
|
|
5640
|
-
#
|
|
5641
|
-
# the "saved $X vs your selection" UX the base rate is the right comparison
|
|
5642
|
-
# — we're measuring the model swap, not the context tier. Used below on the
|
|
5643
|
-
# routed and requested model ids from the decisions log / transcript.
|
|
5685
|
+
# This estimate compares base model prices, not context-tier surcharges.
|
|
5644
5686
|
normalize_model() {
|
|
5645
5687
|
printf '%s' "$1" | sed -E 's/\[[^]]*\]$//; s/-[0-9]{8}$//'
|
|
5646
5688
|
}
|
|
@@ -5666,10 +5708,10 @@ prices='{
|
|
|
5666
5708
|
"claude-sonnet-4-6": 0.003,
|
|
5667
5709
|
"claude-sonnet-5": 0.003,
|
|
5668
5710
|
"claude-sonnet-5-5": 0.002,
|
|
5669
|
-
"deepseek/deepseek-v4-flash": 0.
|
|
5711
|
+
"deepseek/deepseek-v4-flash": 0.00014,
|
|
5670
5712
|
"deepseek/deepseek-v4-pro": 0.00174,
|
|
5671
5713
|
"deepseek/deepseek-v4-pro-0813": 0.00174,
|
|
5672
|
-
"deepseek/deepseek-v4.1-flash": 0.
|
|
5714
|
+
"deepseek/deepseek-v4.1-flash": 0.0002,
|
|
5673
5715
|
"gemini-2.0-flash": 0.0001,
|
|
5674
5716
|
"gemini-2.0-flash-lite": 0.000075,
|
|
5675
5717
|
"gemini-2.5-flash": 0.0003,
|
|
@@ -5710,6 +5752,7 @@ prices='{
|
|
|
5710
5752
|
"gpt-6-astra": 0.01,
|
|
5711
5753
|
"gpt-6-luna": 0.0001,
|
|
5712
5754
|
"gpt-6-sol": 0.002,
|
|
5755
|
+
"gpt-6.1-sol": 0.002,
|
|
5713
5756
|
"grok-4.5": 0.002,
|
|
5714
5757
|
"grok-4.6": 0.002,
|
|
5715
5758
|
"grok-4.7": 0.002,
|
|
@@ -5756,10 +5799,10 @@ prices='{
|
|
|
5756
5799
|
"claude-sonnet-4-6": 0.015,
|
|
5757
5800
|
"claude-sonnet-5": 0.015,
|
|
5758
5801
|
"claude-sonnet-5-5": 0.01,
|
|
5759
|
-
"deepseek/deepseek-v4-flash": 0.
|
|
5802
|
+
"deepseek/deepseek-v4-flash": 0.00028,
|
|
5760
5803
|
"deepseek/deepseek-v4-pro": 0.00348,
|
|
5761
5804
|
"deepseek/deepseek-v4-pro-0813": 0.00348,
|
|
5762
|
-
"deepseek/deepseek-v4.1-flash": 0.
|
|
5805
|
+
"deepseek/deepseek-v4.1-flash": 0.00099,
|
|
5763
5806
|
"gemini-2.0-flash": 0.0004,
|
|
5764
5807
|
"gemini-2.0-flash-lite": 0.0003,
|
|
5765
5808
|
"gemini-2.5-flash": 0.0012,
|
|
@@ -5800,6 +5843,7 @@ prices='{
|
|
|
5800
5843
|
"gpt-6-astra": 0.05,
|
|
5801
5844
|
"gpt-6-luna": 0.0005,
|
|
5802
5845
|
"gpt-6-sol": 0.01,
|
|
5846
|
+
"gpt-6.1-sol": 0.01,
|
|
5803
5847
|
"grok-4.5": 0.006,
|
|
5804
5848
|
"grok-4.6": 0.006,
|
|
5805
5849
|
"grok-4.7": 0.006,
|
|
@@ -5846,10 +5890,10 @@ prices='{
|
|
|
5846
5890
|
"claude-sonnet-4-6": 0.1,
|
|
5847
5891
|
"claude-sonnet-5": 0.1,
|
|
5848
5892
|
"claude-sonnet-5-5": 0.1,
|
|
5849
|
-
"deepseek/deepseek-v4-flash": 0.
|
|
5893
|
+
"deepseek/deepseek-v4-flash": 0.1,
|
|
5850
5894
|
"deepseek/deepseek-v4-pro": 0.0862,
|
|
5851
5895
|
"deepseek/deepseek-v4-pro-0813": 0.0862,
|
|
5852
|
-
"deepseek/deepseek-v4.1-flash": 0.
|
|
5896
|
+
"deepseek/deepseek-v4.1-flash": 0.03,
|
|
5853
5897
|
"gemini-2.0-flash": 0.25,
|
|
5854
5898
|
"gemini-2.0-flash-lite": 0.25,
|
|
5855
5899
|
"gemini-2.5-flash": 0.1,
|
|
@@ -5890,6 +5934,7 @@ prices='{
|
|
|
5890
5934
|
"gpt-6-astra": 0.1,
|
|
5891
5935
|
"gpt-6-luna": 0.1,
|
|
5892
5936
|
"gpt-6-sol": 0.1,
|
|
5937
|
+
"gpt-6.1-sol": 0.05,
|
|
5893
5938
|
"grok-4.5": 0.25,
|
|
5894
5939
|
"grok-4.6": 0.25,
|
|
5895
5940
|
"grok-4.7": 0.25,
|
|
@@ -5923,24 +5968,14 @@ prices='{
|
|
|
5923
5968
|
}'
|
|
5924
5969
|
# END_GENERATED_PRICES
|
|
5925
5970
|
|
|
5926
|
-
|
|
5927
|
-
|
|
5928
|
-
|
|
5929
|
-
|
|
5930
|
-
|
|
5931
|
-
|
|
5932
|
-
|
|
5933
|
-
|
|
5934
|
-
|
|
5935
|
-
# Per-turn savings compare each turn's routed cost (priced from
|
|
5936
|
-
# message.model in the transcript) against what the CC-side model selection
|
|
5937
|
-
# (selected_display) would have cost on the same tokens. The selection
|
|
5938
|
-
# isn't strictly the per-turn "requested" model — CC tags some background
|
|
5939
|
-
# side-calls (compaction probes, title-gen) with a different model id —
|
|
5940
|
-
# but for those the planner short-circuits to a hard pin and the savings
|
|
5941
|
-
# math zeroes out anyway. Turns where routed == selection or where either
|
|
5942
|
-
# model isn't in the pricing table emit 0 savings; the tokens clause
|
|
5943
|
-
# always renders.
|
|
5971
|
+
transcript_model=""
|
|
5972
|
+
has_pin_record="false"
|
|
5973
|
+
last_pin_model=""
|
|
5974
|
+
session_cost_difference=""
|
|
5975
|
+
|
|
5976
|
+
# This is a hypothetical comparison against the CURRENT selection, not
|
|
5977
|
+
# realized router savings: the transcript does not record each turn's
|
|
5978
|
+
# requested model or prove that any turn went through the router.
|
|
5944
5979
|
|
|
5945
5980
|
# Normalize the CC-side selection once for use in the jq math below.
|
|
5946
5981
|
requested_norm="$(normalize_model "$selected_display")"
|
|
@@ -5954,16 +5989,16 @@ if [[ -n "$transcript_path" && -f "$transcript_path" ]]; then
|
|
|
5954
5989
|
# locally (errored requests, cancellations, tool-only stubs) instead of a
|
|
5955
5990
|
# real model id. Show that as "failure" rather than leaking the internal
|
|
5956
5991
|
# sentinel into the statusline.
|
|
5957
|
-
|
|
5992
|
+
transcript_model="$("${reverse[@]}" "$transcript_path" 2>/dev/null \
|
|
5958
5993
|
| jq -r 'select(.type=="assistant") | .message.model // empty' \
|
|
5959
5994
|
| head -n 1 || true)"
|
|
5960
|
-
if [[ "$
|
|
5961
|
-
|
|
5995
|
+
if [[ "$transcript_model" == "<synthetic>" ]]; then
|
|
5996
|
+
transcript_model="failure"
|
|
5962
5997
|
else
|
|
5963
|
-
|
|
5998
|
+
transcript_model="$(normalize_model "$transcript_model")"
|
|
5964
5999
|
fi
|
|
5965
6000
|
|
|
5966
|
-
#
|
|
6001
|
+
# Read the last /force-model acknowledgement in the transcript —
|
|
5967
6002
|
# the only turns stamped message.model == "weave-router". The router emits
|
|
5968
6003
|
# one whenever a pin changes state:
|
|
5969
6004
|
# * /force-model → "force-model applied: <model> (<provider>) …"
|
|
@@ -5982,8 +6017,8 @@ if [[ -n "$transcript_path" && -f "$transcript_path" ]]; then
|
|
|
5982
6017
|
# These persist on disk (the ingress stripper only scrubs them from upstream
|
|
5983
6018
|
# requests). Classify each weave-router turn newest-first, skip the no-op
|
|
5984
6019
|
# "rejected" acks, and let the latest real state change decide: an "applied"
|
|
5985
|
-
# marker
|
|
5986
|
-
#
|
|
6020
|
+
# marker records a pin (and names the model); a later clear removes it.
|
|
6021
|
+
# This history cannot establish the running client's route or current pin.
|
|
5987
6022
|
# Restricting to weave-router turns keeps a normal reply that merely quotes
|
|
5988
6023
|
# these phrases from flipping the tag. (A silent server-side TTL expiry emits
|
|
5989
6024
|
# no turn and so can't be reflected here — the pin TTL outlives a session.)
|
|
@@ -5996,20 +6031,11 @@ if [[ -n "$transcript_path" && -f "$transcript_path" ]]; then
|
|
|
5996
6031
|
else "CLEARED" end' 2>/dev/null \
|
|
5997
6032
|
| grep -m1 -v '^REJECTED$' || true)"
|
|
5998
6033
|
if [[ "$force_state" == APPLIED\ * ]]; then
|
|
5999
|
-
|
|
6000
|
-
|
|
6034
|
+
has_pin_record="true"
|
|
6035
|
+
last_pin_model="${force_state#APPLIED }"
|
|
6001
6036
|
fi
|
|
6002
6037
|
|
|
6003
|
-
#
|
|
6004
|
-
# whose marker reports a requested ≠ routed swap, plus cumulative token
|
|
6005
|
-
# counts across every assistant turn (rerouted or not — total work the
|
|
6006
|
-
# session has done). cache_creation is priced at 1.25× input; cache_read
|
|
6007
|
-
# uses each model's generated catalog multiplier. Both are no-ops when the
|
|
6008
|
-
# provider does not return those fields.
|
|
6009
|
-
#
|
|
6010
|
-
# The marker regex tolerates the optional "(<provider>)" segment and a
|
|
6011
|
-
# `[1m]` / `-YYYYMMDD` suffix on either model name so transcripts written
|
|
6012
|
-
# against context-tiered or dated model ids still parse cleanly.
|
|
6038
|
+
# Missing prices leave the comparison unknown without hiding the model.
|
|
6013
6039
|
#
|
|
6014
6040
|
# Dedup note: CC writes one JSONL entry per *content block* in an
|
|
6015
6041
|
# assistant turn (text, text, tool_use → 3 entries), and every entry
|
|
@@ -6023,9 +6049,9 @@ if [[ -n "$transcript_path" && -f "$transcript_path" ]]; then
|
|
|
6023
6049
|
# grows), so the composite key keeps turns distinct. Two turns with
|
|
6024
6050
|
# byte-identical id AND usage would still collapse, but that's a
|
|
6025
6051
|
# genuine retry/duplicate we want to drop.
|
|
6026
|
-
|
|
6052
|
+
session_cost_difference="$(
|
|
6027
6053
|
jq -rs --argjson p "$prices" --arg requested "$requested_norm" '
|
|
6028
|
-
[.[] | select(.type=="assistant")] |
|
|
6054
|
+
[.[] | select(.type=="assistant" and .message.model!="<synthetic>" and .message.model!="weave-router")] |
|
|
6029
6055
|
unique_by([.message.id, .message.usage]) |
|
|
6030
6056
|
.[] |
|
|
6031
6057
|
.message as $m |
|
|
@@ -6036,13 +6062,13 @@ if [[ -n "$transcript_path" && -f "$transcript_path" ]]; then
|
|
|
6036
6062
|
cwrt: ($m.usage.cache_creation_input_tokens // 0),
|
|
6037
6063
|
crd: ($m.usage.cache_read_input_tokens // 0)
|
|
6038
6064
|
} as $t |
|
|
6039
|
-
(if $
|
|
6065
|
+
(if ($t.in + $t.out + $t.cwrt + $t.crd) == 0 then 0
|
|
6040
6066
|
else
|
|
6041
6067
|
($p.input[$rm] // null) as $rin | ($p.output[$rm] // null) as $rout |
|
|
6042
6068
|
($p.cache_read[$rm] // null) as $rcr |
|
|
6043
6069
|
($p.input[$requested] // null) as $sin | ($p.output[$requested] // null) as $sout |
|
|
6044
6070
|
($p.cache_read[$requested] // null) as $scr |
|
|
6045
|
-
if ($rin == null or $rout == null or $rcr == null or $sin == null or $sout == null or $scr == null) then
|
|
6071
|
+
if ($rin == null or $rout == null or $rcr == null or $sin == null or $sout == null or $scr == null) then null
|
|
6046
6072
|
else
|
|
6047
6073
|
(($t.in + 1.25 * $t.cwrt + $rcr * $t.crd) / 1000) as $routed_input_units |
|
|
6048
6074
|
(($t.in + 1.25 * $t.cwrt + $scr * $t.crd) / 1000) as $requested_input_units |
|
|
@@ -6052,21 +6078,20 @@ if [[ -n "$transcript_path" && -f "$transcript_path" ]]; then
|
|
|
6052
6078
|
($requested_cost - $routed_cost)
|
|
6053
6079
|
end
|
|
6054
6080
|
end) as $savings |
|
|
6055
|
-
|
|
6081
|
+
if $savings == null then "unknown" else $savings end
|
|
6056
6082
|
' "$transcript_path" 2>/dev/null \
|
|
6057
|
-
| awk 'BEGIN{s=0
|
|
6058
|
-
{
|
|
6059
|
-
END{
|
|
6060
|
-
|
|
6083
|
+
| awk 'BEGIN{s=0}
|
|
6084
|
+
{if ($1 == "unknown") comparison_unknown=1; else s+=$1}
|
|
6085
|
+
END{
|
|
6086
|
+
if (NR == 0 || comparison_unknown) printf "unknown"; else printf "%.4f", s;
|
|
6087
|
+
}'
|
|
6088
|
+
)" || true
|
|
6061
6089
|
fi
|
|
6062
6090
|
|
|
6063
6091
|
# ---------- refresh when a model isn't in the pricing table ----------
|
|
6064
6092
|
#
|
|
6065
|
-
# A model
|
|
6066
|
-
#
|
|
6067
|
-
# — indistinguishable from "the router ran and didn't beat your selection". The
|
|
6068
|
-
# periodic check heals that eventually, but a week late, and a model launch is
|
|
6069
|
-
# exactly when the number gets looked at. Refresh off-schedule instead.
|
|
6093
|
+
# A model missing from this copy's price table cannot be compared. Refresh
|
|
6094
|
+
# off-schedule instead of waiting up to a week for the periodic check.
|
|
6070
6095
|
#
|
|
6071
6096
|
# Keyed on its own stamp per unpriced id: a model we never price (self-hosted,
|
|
6072
6097
|
# unrecognized) then costs one download per interval, not one per turn, and
|
|
@@ -6094,7 +6119,7 @@ weave_refresh_on_price_miss() {
|
|
|
6094
6119
|
model_slug="$(printf '%s' "$missing" | tr -c 'A-Za-z0-9._-' '_')"
|
|
6095
6120
|
weave_self_refresh ".miss.${model_slug}" 1
|
|
6096
6121
|
}
|
|
6097
|
-
weave_refresh_on_price_miss "$requested_norm" "$
|
|
6122
|
+
weave_refresh_on_price_miss "$requested_norm" "$transcript_model" 2>/dev/null || true
|
|
6098
6123
|
|
|
6099
6124
|
# Brand color (#FF6C47) on terminals that grok 24-bit truecolor — that's
|
|
6100
6125
|
# every modern one (iTerm2, Apple Terminal, vscode, ghostty, alacritty,
|
|
@@ -6105,73 +6130,28 @@ brand=$'\033[38;2;255;108;71mWEAVE ROUTER\033[0m'
|
|
|
6105
6130
|
fmt_money() {
|
|
6106
6131
|
awk -v v="$1" 'BEGIN{
|
|
6107
6132
|
if (v == "" || v+0 == 0) { printf "$0.00"; exit }
|
|
6108
|
-
if (v+0 < 0.005 && v+0 > -0.005){ printf "<$0.01";
|
|
6133
|
+
if (v+0 < 0.005 && v+0 > -0.005){ printf "%s<$0.01", (v+0 < 0 ? "-" : ""); exit }
|
|
6109
6134
|
if (v+0 < 0) { printf "-$%.2f", -v+0; exit }
|
|
6110
6135
|
printf "$%.2f", v
|
|
6111
6136
|
}'
|
|
6112
6137
|
}
|
|
6113
6138
|
|
|
6114
|
-
|
|
6115
|
-
|
|
6116
|
-
|
|
6117
|
-
|
|
6118
|
-
|
|
6119
|
-
|
|
6120
|
-
|
|
6121
|
-
}
|
|
6122
|
-
|
|
6123
|
-
# cache_read tokens are the cached portion of every prompt that the
|
|
6124
|
-
# provider serves at 0.1× input price; cache_write tokens are the bytes
|
|
6125
|
-
# that get newly cached on this turn at 1.25× input price. They behave
|
|
6126
|
-
# completely differently both in cost and in what they tell the user
|
|
6127
|
-
# about session-level efficiency, so we surface them separately rather
|
|
6128
|
-
# than summing into a single "cached" number that conflates the two.
|
|
6129
|
-
# Each clause is shown only when nonzero, so quiet sessions stay quiet.
|
|
6130
|
-
tokens_clause=""
|
|
6131
|
-
if [[ "$tot_in" -gt 0 || "$tot_out" -gt 0 || "$tot_cache_read" -gt 0 || "$tot_cache_write" -gt 0 ]]; then
|
|
6132
|
-
tokens_clause=" · $(fmt_tok "$tot_in") in / $(fmt_tok "$tot_out") out"
|
|
6133
|
-
if [[ "$tot_cache_read" -gt 0 ]]; then
|
|
6134
|
-
tokens_clause+=" / $(fmt_tok "$tot_cache_read") cache read"
|
|
6135
|
-
fi
|
|
6136
|
-
if [[ "$tot_cache_write" -gt 0 ]]; then
|
|
6137
|
-
tokens_clause+=" / $(fmt_tok "$tot_cache_write") cache write"
|
|
6138
|
-
fi
|
|
6139
|
+
printf '%s' "$brand"
|
|
6140
|
+
if [[ "$transcript_model" == "failure" ]]; then
|
|
6141
|
+
printf ' · last response failed'
|
|
6142
|
+
elif [[ "$transcript_model" == "weave-router" ]]; then
|
|
6143
|
+
printf ' · control acknowledgement'
|
|
6144
|
+
elif [[ -n "$transcript_model" ]]; then
|
|
6145
|
+
printf ' · response model: %s' "$transcript_model"
|
|
6139
6146
|
fi
|
|
6140
|
-
|
|
6141
|
-
|
|
6142
|
-
|
|
6143
|
-
|
|
6144
|
-
|
|
6145
|
-
|
|
6146
|
-
|
|
6147
|
-
printf '
|
|
6148
|
-
elif [[ "$routed" == "failure" ]]; then
|
|
6149
|
-
# Latest turn was a CC-synthesized error stub — don't claim a routing
|
|
6150
|
-
# swap or compute savings against a non-model.
|
|
6151
|
-
printf '%s — %s%s' "$brand" "$routed" "$tokens_clause"
|
|
6152
|
-
elif [[ -n "$routed" ]]; then
|
|
6153
|
-
# Always show the savings clause, flooring a non-positive total at $0.00.
|
|
6154
|
-
# session_savings is "0.0000" on fresh sessions or sessions where every
|
|
6155
|
-
# turn routed back to the selected model, and can go negative when routing
|
|
6156
|
-
# upgrades a turn to a pricier model (e.g. a sticky/hard-pinned side-call,
|
|
6157
|
-
# or a hard turn escalated to opus). "saved -$X" would mislead, so clamp
|
|
6158
|
-
# the display to $0.00 rather than dropping the clause — a $0.00 readout
|
|
6159
|
-
# tells the user the router ran and simply didn't beat their selection.
|
|
6160
|
-
# When the CC selection is unknown ("?" or empty) there's nothing to
|
|
6161
|
-
# compare against, so drop the "← selection" arrow and just show routed.
|
|
6162
|
-
display_savings="$session_savings"
|
|
6163
|
-
if [[ -z "$display_savings" ]] \
|
|
6164
|
-
|| awk -v v="$display_savings" 'BEGIN{exit !(v+0 < 0)}'; then
|
|
6165
|
-
display_savings="0"
|
|
6166
|
-
fi
|
|
6167
|
-
if [[ -n "$selected_display" && "$selected_display" != "?" ]]; then
|
|
6168
|
-
printf '%s — %s ← %s · saved %s%s' \
|
|
6169
|
-
"$brand" "$routed" "$selected_display" "$(fmt_money "$display_savings")" "$tokens_clause"
|
|
6170
|
-
else
|
|
6171
|
-
printf '%s — %s%s' "$brand" "$routed" "$tokens_clause"
|
|
6172
|
-
fi
|
|
6173
|
-
else
|
|
6174
|
-
printf '%s — %s%s' "$brand" "$selected_display" "$tokens_clause"
|
|
6147
|
+
if [[ -n "$selected_display" && "$selected_display" != "?" ]]; then
|
|
6148
|
+
printf ' · selected: %s' "$selected_display"
|
|
6149
|
+
fi
|
|
6150
|
+
if [[ -n "$session_cost_difference" && "$session_cost_difference" != "unknown" && "$transcript_model" != "failure" && "$transcript_model" != "weave-router" ]]; then
|
|
6151
|
+
printf ' · est. cost difference %s' "$(fmt_money "$session_cost_difference")"
|
|
6152
|
+
fi
|
|
6153
|
+
if [[ "$has_pin_record" == "true" ]]; then
|
|
6154
|
+
printf ' · last pin: %s' "$last_pin_model"
|
|
6175
6155
|
fi
|
|
6176
6156
|
STATUSLINE_EOF
|
|
6177
6157
|
chmod +x "$statusline_file"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@weave-os/router",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.29",
|
|
4
4
|
"description": "One-command installer that points Claude Code, Codex, opencode, or pi at the Weave Router. For pi it also ships the routing extension, loaded via pi.extensions.",
|
|
5
5
|
"bin": {
|
|
6
6
|
"weave-router": "bin.js",
|
|
@@ -7,7 +7,7 @@ export interface ModelPricing {
|
|
|
7
7
|
cacheReadMultiplier: number;
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
export const PRICING_VERSION = "catalog-sha256:
|
|
10
|
+
export const PRICING_VERSION = "catalog-sha256:9784eadb00c29643";
|
|
11
11
|
|
|
12
12
|
export const MODEL_PRICING: Readonly<Record<string, ModelPricing>> = Object.freeze({
|
|
13
13
|
"claude-fable-5": { inputUsdPerMillion: 10, outputUsdPerMillion: 50, cacheReadMultiplier: 0.1 },
|
|
@@ -25,10 +25,10 @@ export const MODEL_PRICING: Readonly<Record<string, ModelPricing>> = Object.free
|
|
|
25
25
|
"claude-sonnet-4-6": { inputUsdPerMillion: 3, outputUsdPerMillion: 15, cacheReadMultiplier: 0.1 },
|
|
26
26
|
"claude-sonnet-5": { inputUsdPerMillion: 3, outputUsdPerMillion: 15, cacheReadMultiplier: 0.1 },
|
|
27
27
|
"claude-sonnet-5-5": { inputUsdPerMillion: 2, outputUsdPerMillion: 10, cacheReadMultiplier: 0.1 },
|
|
28
|
-
"deepseek/deepseek-v4-flash": { inputUsdPerMillion: 0.
|
|
28
|
+
"deepseek/deepseek-v4-flash": { inputUsdPerMillion: 0.14, outputUsdPerMillion: 0.28, cacheReadMultiplier: 0.1 },
|
|
29
29
|
"deepseek/deepseek-v4-pro": { inputUsdPerMillion: 1.74, outputUsdPerMillion: 3.48, cacheReadMultiplier: 0.0862 },
|
|
30
30
|
"deepseek/deepseek-v4-pro-0813": { inputUsdPerMillion: 1.74, outputUsdPerMillion: 3.48, cacheReadMultiplier: 0.0862 },
|
|
31
|
-
"deepseek/deepseek-v4.1-flash": { inputUsdPerMillion: 0.
|
|
31
|
+
"deepseek/deepseek-v4.1-flash": { inputUsdPerMillion: 0.2, outputUsdPerMillion: 0.99, cacheReadMultiplier: 0.03 },
|
|
32
32
|
"gemini-2.0-flash": { inputUsdPerMillion: 0.1, outputUsdPerMillion: 0.4, cacheReadMultiplier: 0.25 },
|
|
33
33
|
"gemini-2.0-flash-lite": { inputUsdPerMillion: 0.075, outputUsdPerMillion: 0.3, cacheReadMultiplier: 0.25 },
|
|
34
34
|
"gemini-2.5-flash": { inputUsdPerMillion: 0.3, outputUsdPerMillion: 1.2, cacheReadMultiplier: 0.1 },
|
|
@@ -69,6 +69,7 @@ export const MODEL_PRICING: Readonly<Record<string, ModelPricing>> = Object.free
|
|
|
69
69
|
"gpt-6-astra": { inputUsdPerMillion: 10, outputUsdPerMillion: 50, cacheReadMultiplier: 0.1 },
|
|
70
70
|
"gpt-6-luna": { inputUsdPerMillion: 0.1, outputUsdPerMillion: 0.5, cacheReadMultiplier: 0.1 },
|
|
71
71
|
"gpt-6-sol": { inputUsdPerMillion: 2, outputUsdPerMillion: 10, cacheReadMultiplier: 0.1 },
|
|
72
|
+
"gpt-6.1-sol": { inputUsdPerMillion: 2, outputUsdPerMillion: 10, cacheReadMultiplier: 0.05 },
|
|
72
73
|
"grok-4.5": { inputUsdPerMillion: 2, outputUsdPerMillion: 6, cacheReadMultiplier: 0.25 },
|
|
73
74
|
"grok-4.6": { inputUsdPerMillion: 2, outputUsdPerMillion: 6, cacheReadMultiplier: 0.25 },
|
|
74
75
|
"grok-4.7": { inputUsdPerMillion: 2, outputUsdPerMillion: 6, cacheReadMultiplier: 0.25 },
|