@weave-os/router 0.2.28 → 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 +118 -136
- 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
|
|
@@ -3553,7 +3601,7 @@ run_login() {
|
|
|
3553
3601
|
extra="$(printf '%s\n' "$models_args" | tail -n +2)"
|
|
3554
3602
|
[ -n "$provider" ] || { err "Use 'login claude' or 'login codex'."; exit 2; }
|
|
3555
3603
|
[ -z "$extra" ] || { err "Login accepts exactly one provider."; exit 2; }
|
|
3556
|
-
|
|
3604
|
+
ensure_jq
|
|
3557
3605
|
require_cmd openssl "Install OpenSSL to enroll a subscription account."
|
|
3558
3606
|
case "$provider" in
|
|
3559
3607
|
claude) run_login_claude ;;
|
|
@@ -4316,6 +4364,7 @@ install_codex_status_script() {
|
|
|
4316
4364
|
# blocks on the network, and every failure path leaves the title model-only.
|
|
4317
4365
|
|
|
4318
4366
|
set -euo pipefail
|
|
4367
|
+
export PATH="$PATH:$HOME/.weave/bin"
|
|
4319
4368
|
|
|
4320
4369
|
# ---------- background self-refresh ----------
|
|
4321
4370
|
#
|
|
@@ -4799,6 +4848,7 @@ install_codex_directive_script() {
|
|
|
4799
4848
|
# fire.
|
|
4800
4849
|
|
|
4801
4850
|
set -uo pipefail
|
|
4851
|
+
export PATH="$PATH:$HOME/.weave/bin"
|
|
4802
4852
|
|
|
4803
4853
|
# How long the toggle may take before the hook gives up and passes the prompt
|
|
4804
4854
|
# through. npx resolves from cache after first use; the budget covers a cold
|
|
@@ -5184,26 +5234,23 @@ cat > "$statusline_file" << 'STATUSLINE_EOF'
|
|
|
5184
5234
|
#!/usr/bin/env bash
|
|
5185
5235
|
#
|
|
5186
5236
|
# Claude Code statusline for the Weave Router. CC pipes a JSON blob on stdin
|
|
5187
|
-
# whose `transcript_path` points at the JSONL log
|
|
5188
|
-
#
|
|
5189
|
-
#
|
|
5190
|
-
#
|
|
5191
|
-
# stream and CC stores that in the transcript verbatim. Per-turn savings
|
|
5192
|
-
# come from comparing each turn's routed cost against what the user's
|
|
5193
|
-
# selection would have cost on the same tokens. Works identically for
|
|
5194
|
-
# 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.
|
|
5195
5241
|
#
|
|
5196
5242
|
# Wire up by adding to ~/.claude/settings.json:
|
|
5197
5243
|
# { "statusLine": { "type": "command", "command": "/abs/path/to/cc-statusline.sh" } }
|
|
5198
5244
|
#
|
|
5199
5245
|
# Renders:
|
|
5200
|
-
# WEAVE ROUTER
|
|
5246
|
+
# WEAVE ROUTER · response model: claude-sonnet-4-5 · selected: claude-opus-4-7 · est. cost difference $1.23
|
|
5201
5247
|
#
|
|
5202
5248
|
# Pricing source of truth: internal/router/catalog. Input/output prices and
|
|
5203
5249
|
# cache-read multipliers are generated by cmd/genprices. Cache creation remains
|
|
5204
5250
|
# at 1.25× input pending TTL-aware pricing.
|
|
5205
5251
|
|
|
5206
5252
|
set -euo pipefail
|
|
5253
|
+
export PATH="$PATH:$HOME/.weave/bin"
|
|
5207
5254
|
|
|
5208
5255
|
# ---------- background self-refresh ----------
|
|
5209
5256
|
#
|
|
@@ -5625,20 +5672,17 @@ fi
|
|
|
5625
5672
|
|
|
5626
5673
|
input="$(cat)"
|
|
5627
5674
|
transcript_path="$(printf '%s' "$input" | jq -r '.transcript_path // empty')"
|
|
5628
|
-
# Prefer model.id over display_name: pricing keys + the
|
|
5675
|
+
# Prefer model.id over display_name: pricing keys + the response model id in
|
|
5629
5676
|
# the transcript are canonical ids (e.g. claude-opus-4-7), while display_name
|
|
5630
5677
|
# is a human label ("Opus 4.7 (1M context)") that won't hit the pricing table,
|
|
5631
|
-
#
|
|
5678
|
+
# preventing a price comparison. id passes through normalize_model cleanly.
|
|
5632
5679
|
selected_display="$(printf '%s' "$input" | jq -r '.model.id // .model.display_name // "?"')"
|
|
5633
5680
|
|
|
5634
5681
|
# Normalize a model id to a pricing-table key. CC + the decisions log carry
|
|
5635
5682
|
# two flavors of annotation we don't want in the lookup:
|
|
5636
5683
|
# * date suffix: claude-opus-4-7-20260101 → claude-opus-4-7
|
|
5637
5684
|
# * variant tag: claude-opus-4-7[1m] → claude-opus-4-7
|
|
5638
|
-
#
|
|
5639
|
-
# the "saved $X vs your selection" UX the base rate is the right comparison
|
|
5640
|
-
# — we're measuring the model swap, not the context tier. Used below on the
|
|
5641
|
-
# routed and requested model ids from the decisions log / transcript.
|
|
5685
|
+
# This estimate compares base model prices, not context-tier surcharges.
|
|
5642
5686
|
normalize_model() {
|
|
5643
5687
|
printf '%s' "$1" | sed -E 's/\[[^]]*\]$//; s/-[0-9]{8}$//'
|
|
5644
5688
|
}
|
|
@@ -5664,10 +5708,10 @@ prices='{
|
|
|
5664
5708
|
"claude-sonnet-4-6": 0.003,
|
|
5665
5709
|
"claude-sonnet-5": 0.003,
|
|
5666
5710
|
"claude-sonnet-5-5": 0.002,
|
|
5667
|
-
"deepseek/deepseek-v4-flash": 0.
|
|
5711
|
+
"deepseek/deepseek-v4-flash": 0.00014,
|
|
5668
5712
|
"deepseek/deepseek-v4-pro": 0.00174,
|
|
5669
5713
|
"deepseek/deepseek-v4-pro-0813": 0.00174,
|
|
5670
|
-
"deepseek/deepseek-v4.1-flash": 0.
|
|
5714
|
+
"deepseek/deepseek-v4.1-flash": 0.0002,
|
|
5671
5715
|
"gemini-2.0-flash": 0.0001,
|
|
5672
5716
|
"gemini-2.0-flash-lite": 0.000075,
|
|
5673
5717
|
"gemini-2.5-flash": 0.0003,
|
|
@@ -5708,6 +5752,7 @@ prices='{
|
|
|
5708
5752
|
"gpt-6-astra": 0.01,
|
|
5709
5753
|
"gpt-6-luna": 0.0001,
|
|
5710
5754
|
"gpt-6-sol": 0.002,
|
|
5755
|
+
"gpt-6.1-sol": 0.002,
|
|
5711
5756
|
"grok-4.5": 0.002,
|
|
5712
5757
|
"grok-4.6": 0.002,
|
|
5713
5758
|
"grok-4.7": 0.002,
|
|
@@ -5754,10 +5799,10 @@ prices='{
|
|
|
5754
5799
|
"claude-sonnet-4-6": 0.015,
|
|
5755
5800
|
"claude-sonnet-5": 0.015,
|
|
5756
5801
|
"claude-sonnet-5-5": 0.01,
|
|
5757
|
-
"deepseek/deepseek-v4-flash": 0.
|
|
5802
|
+
"deepseek/deepseek-v4-flash": 0.00028,
|
|
5758
5803
|
"deepseek/deepseek-v4-pro": 0.00348,
|
|
5759
5804
|
"deepseek/deepseek-v4-pro-0813": 0.00348,
|
|
5760
|
-
"deepseek/deepseek-v4.1-flash": 0.
|
|
5805
|
+
"deepseek/deepseek-v4.1-flash": 0.00099,
|
|
5761
5806
|
"gemini-2.0-flash": 0.0004,
|
|
5762
5807
|
"gemini-2.0-flash-lite": 0.0003,
|
|
5763
5808
|
"gemini-2.5-flash": 0.0012,
|
|
@@ -5798,6 +5843,7 @@ prices='{
|
|
|
5798
5843
|
"gpt-6-astra": 0.05,
|
|
5799
5844
|
"gpt-6-luna": 0.0005,
|
|
5800
5845
|
"gpt-6-sol": 0.01,
|
|
5846
|
+
"gpt-6.1-sol": 0.01,
|
|
5801
5847
|
"grok-4.5": 0.006,
|
|
5802
5848
|
"grok-4.6": 0.006,
|
|
5803
5849
|
"grok-4.7": 0.006,
|
|
@@ -5844,10 +5890,10 @@ prices='{
|
|
|
5844
5890
|
"claude-sonnet-4-6": 0.1,
|
|
5845
5891
|
"claude-sonnet-5": 0.1,
|
|
5846
5892
|
"claude-sonnet-5-5": 0.1,
|
|
5847
|
-
"deepseek/deepseek-v4-flash": 0.
|
|
5893
|
+
"deepseek/deepseek-v4-flash": 0.1,
|
|
5848
5894
|
"deepseek/deepseek-v4-pro": 0.0862,
|
|
5849
5895
|
"deepseek/deepseek-v4-pro-0813": 0.0862,
|
|
5850
|
-
"deepseek/deepseek-v4.1-flash": 0.
|
|
5896
|
+
"deepseek/deepseek-v4.1-flash": 0.03,
|
|
5851
5897
|
"gemini-2.0-flash": 0.25,
|
|
5852
5898
|
"gemini-2.0-flash-lite": 0.25,
|
|
5853
5899
|
"gemini-2.5-flash": 0.1,
|
|
@@ -5888,6 +5934,7 @@ prices='{
|
|
|
5888
5934
|
"gpt-6-astra": 0.1,
|
|
5889
5935
|
"gpt-6-luna": 0.1,
|
|
5890
5936
|
"gpt-6-sol": 0.1,
|
|
5937
|
+
"gpt-6.1-sol": 0.05,
|
|
5891
5938
|
"grok-4.5": 0.25,
|
|
5892
5939
|
"grok-4.6": 0.25,
|
|
5893
5940
|
"grok-4.7": 0.25,
|
|
@@ -5921,24 +5968,14 @@ prices='{
|
|
|
5921
5968
|
}'
|
|
5922
5969
|
# END_GENERATED_PRICES
|
|
5923
5970
|
|
|
5924
|
-
|
|
5925
|
-
|
|
5926
|
-
|
|
5927
|
-
|
|
5928
|
-
|
|
5929
|
-
|
|
5930
|
-
|
|
5931
|
-
|
|
5932
|
-
|
|
5933
|
-
# Per-turn savings compare each turn's routed cost (priced from
|
|
5934
|
-
# message.model in the transcript) against what the CC-side model selection
|
|
5935
|
-
# (selected_display) would have cost on the same tokens. The selection
|
|
5936
|
-
# isn't strictly the per-turn "requested" model — CC tags some background
|
|
5937
|
-
# side-calls (compaction probes, title-gen) with a different model id —
|
|
5938
|
-
# but for those the planner short-circuits to a hard pin and the savings
|
|
5939
|
-
# math zeroes out anyway. Turns where routed == selection or where either
|
|
5940
|
-
# model isn't in the pricing table emit 0 savings; the tokens clause
|
|
5941
|
-
# 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.
|
|
5942
5979
|
|
|
5943
5980
|
# Normalize the CC-side selection once for use in the jq math below.
|
|
5944
5981
|
requested_norm="$(normalize_model "$selected_display")"
|
|
@@ -5952,16 +5989,16 @@ if [[ -n "$transcript_path" && -f "$transcript_path" ]]; then
|
|
|
5952
5989
|
# locally (errored requests, cancellations, tool-only stubs) instead of a
|
|
5953
5990
|
# real model id. Show that as "failure" rather than leaking the internal
|
|
5954
5991
|
# sentinel into the statusline.
|
|
5955
|
-
|
|
5992
|
+
transcript_model="$("${reverse[@]}" "$transcript_path" 2>/dev/null \
|
|
5956
5993
|
| jq -r 'select(.type=="assistant") | .message.model // empty' \
|
|
5957
5994
|
| head -n 1 || true)"
|
|
5958
|
-
if [[ "$
|
|
5959
|
-
|
|
5995
|
+
if [[ "$transcript_model" == "<synthetic>" ]]; then
|
|
5996
|
+
transcript_model="failure"
|
|
5960
5997
|
else
|
|
5961
|
-
|
|
5998
|
+
transcript_model="$(normalize_model "$transcript_model")"
|
|
5962
5999
|
fi
|
|
5963
6000
|
|
|
5964
|
-
#
|
|
6001
|
+
# Read the last /force-model acknowledgement in the transcript —
|
|
5965
6002
|
# the only turns stamped message.model == "weave-router". The router emits
|
|
5966
6003
|
# one whenever a pin changes state:
|
|
5967
6004
|
# * /force-model → "force-model applied: <model> (<provider>) …"
|
|
@@ -5980,8 +6017,8 @@ if [[ -n "$transcript_path" && -f "$transcript_path" ]]; then
|
|
|
5980
6017
|
# These persist on disk (the ingress stripper only scrubs them from upstream
|
|
5981
6018
|
# requests). Classify each weave-router turn newest-first, skip the no-op
|
|
5982
6019
|
# "rejected" acks, and let the latest real state change decide: an "applied"
|
|
5983
|
-
# marker
|
|
5984
|
-
#
|
|
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.
|
|
5985
6022
|
# Restricting to weave-router turns keeps a normal reply that merely quotes
|
|
5986
6023
|
# these phrases from flipping the tag. (A silent server-side TTL expiry emits
|
|
5987
6024
|
# no turn and so can't be reflected here — the pin TTL outlives a session.)
|
|
@@ -5994,20 +6031,11 @@ if [[ -n "$transcript_path" && -f "$transcript_path" ]]; then
|
|
|
5994
6031
|
else "CLEARED" end' 2>/dev/null \
|
|
5995
6032
|
| grep -m1 -v '^REJECTED$' || true)"
|
|
5996
6033
|
if [[ "$force_state" == APPLIED\ * ]]; then
|
|
5997
|
-
|
|
5998
|
-
|
|
6034
|
+
has_pin_record="true"
|
|
6035
|
+
last_pin_model="${force_state#APPLIED }"
|
|
5999
6036
|
fi
|
|
6000
6037
|
|
|
6001
|
-
#
|
|
6002
|
-
# whose marker reports a requested ≠ routed swap, plus cumulative token
|
|
6003
|
-
# counts across every assistant turn (rerouted or not — total work the
|
|
6004
|
-
# session has done). cache_creation is priced at 1.25× input; cache_read
|
|
6005
|
-
# uses each model's generated catalog multiplier. Both are no-ops when the
|
|
6006
|
-
# provider does not return those fields.
|
|
6007
|
-
#
|
|
6008
|
-
# The marker regex tolerates the optional "(<provider>)" segment and a
|
|
6009
|
-
# `[1m]` / `-YYYYMMDD` suffix on either model name so transcripts written
|
|
6010
|
-
# against context-tiered or dated model ids still parse cleanly.
|
|
6038
|
+
# Missing prices leave the comparison unknown without hiding the model.
|
|
6011
6039
|
#
|
|
6012
6040
|
# Dedup note: CC writes one JSONL entry per *content block* in an
|
|
6013
6041
|
# assistant turn (text, text, tool_use → 3 entries), and every entry
|
|
@@ -6021,9 +6049,9 @@ if [[ -n "$transcript_path" && -f "$transcript_path" ]]; then
|
|
|
6021
6049
|
# grows), so the composite key keeps turns distinct. Two turns with
|
|
6022
6050
|
# byte-identical id AND usage would still collapse, but that's a
|
|
6023
6051
|
# genuine retry/duplicate we want to drop.
|
|
6024
|
-
|
|
6052
|
+
session_cost_difference="$(
|
|
6025
6053
|
jq -rs --argjson p "$prices" --arg requested "$requested_norm" '
|
|
6026
|
-
[.[] | select(.type=="assistant")] |
|
|
6054
|
+
[.[] | select(.type=="assistant" and .message.model!="<synthetic>" and .message.model!="weave-router")] |
|
|
6027
6055
|
unique_by([.message.id, .message.usage]) |
|
|
6028
6056
|
.[] |
|
|
6029
6057
|
.message as $m |
|
|
@@ -6034,13 +6062,13 @@ if [[ -n "$transcript_path" && -f "$transcript_path" ]]; then
|
|
|
6034
6062
|
cwrt: ($m.usage.cache_creation_input_tokens // 0),
|
|
6035
6063
|
crd: ($m.usage.cache_read_input_tokens // 0)
|
|
6036
6064
|
} as $t |
|
|
6037
|
-
(if $
|
|
6065
|
+
(if ($t.in + $t.out + $t.cwrt + $t.crd) == 0 then 0
|
|
6038
6066
|
else
|
|
6039
6067
|
($p.input[$rm] // null) as $rin | ($p.output[$rm] // null) as $rout |
|
|
6040
6068
|
($p.cache_read[$rm] // null) as $rcr |
|
|
6041
6069
|
($p.input[$requested] // null) as $sin | ($p.output[$requested] // null) as $sout |
|
|
6042
6070
|
($p.cache_read[$requested] // null) as $scr |
|
|
6043
|
-
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
|
|
6044
6072
|
else
|
|
6045
6073
|
(($t.in + 1.25 * $t.cwrt + $rcr * $t.crd) / 1000) as $routed_input_units |
|
|
6046
6074
|
(($t.in + 1.25 * $t.cwrt + $scr * $t.crd) / 1000) as $requested_input_units |
|
|
@@ -6050,21 +6078,20 @@ if [[ -n "$transcript_path" && -f "$transcript_path" ]]; then
|
|
|
6050
6078
|
($requested_cost - $routed_cost)
|
|
6051
6079
|
end
|
|
6052
6080
|
end) as $savings |
|
|
6053
|
-
|
|
6081
|
+
if $savings == null then "unknown" else $savings end
|
|
6054
6082
|
' "$transcript_path" 2>/dev/null \
|
|
6055
|
-
| awk 'BEGIN{s=0
|
|
6056
|
-
{
|
|
6057
|
-
END{
|
|
6058
|
-
|
|
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
|
|
6059
6089
|
fi
|
|
6060
6090
|
|
|
6061
6091
|
# ---------- refresh when a model isn't in the pricing table ----------
|
|
6062
6092
|
#
|
|
6063
|
-
# A model
|
|
6064
|
-
#
|
|
6065
|
-
# — indistinguishable from "the router ran and didn't beat your selection". The
|
|
6066
|
-
# periodic check heals that eventually, but a week late, and a model launch is
|
|
6067
|
-
# 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.
|
|
6068
6095
|
#
|
|
6069
6096
|
# Keyed on its own stamp per unpriced id: a model we never price (self-hosted,
|
|
6070
6097
|
# unrecognized) then costs one download per interval, not one per turn, and
|
|
@@ -6092,7 +6119,7 @@ weave_refresh_on_price_miss() {
|
|
|
6092
6119
|
model_slug="$(printf '%s' "$missing" | tr -c 'A-Za-z0-9._-' '_')"
|
|
6093
6120
|
weave_self_refresh ".miss.${model_slug}" 1
|
|
6094
6121
|
}
|
|
6095
|
-
weave_refresh_on_price_miss "$requested_norm" "$
|
|
6122
|
+
weave_refresh_on_price_miss "$requested_norm" "$transcript_model" 2>/dev/null || true
|
|
6096
6123
|
|
|
6097
6124
|
# Brand color (#FF6C47) on terminals that grok 24-bit truecolor — that's
|
|
6098
6125
|
# every modern one (iTerm2, Apple Terminal, vscode, ghostty, alacritty,
|
|
@@ -6103,73 +6130,28 @@ brand=$'\033[38;2;255;108;71mWEAVE ROUTER\033[0m'
|
|
|
6103
6130
|
fmt_money() {
|
|
6104
6131
|
awk -v v="$1" 'BEGIN{
|
|
6105
6132
|
if (v == "" || v+0 == 0) { printf "$0.00"; exit }
|
|
6106
|
-
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 }
|
|
6107
6134
|
if (v+0 < 0) { printf "-$%.2f", -v+0; exit }
|
|
6108
6135
|
printf "$%.2f", v
|
|
6109
6136
|
}'
|
|
6110
6137
|
}
|
|
6111
6138
|
|
|
6112
|
-
|
|
6113
|
-
|
|
6114
|
-
|
|
6115
|
-
|
|
6116
|
-
|
|
6117
|
-
|
|
6118
|
-
|
|
6119
|
-
}
|
|
6120
|
-
|
|
6121
|
-
# cache_read tokens are the cached portion of every prompt that the
|
|
6122
|
-
# provider serves at 0.1× input price; cache_write tokens are the bytes
|
|
6123
|
-
# that get newly cached on this turn at 1.25× input price. They behave
|
|
6124
|
-
# completely differently both in cost and in what they tell the user
|
|
6125
|
-
# about session-level efficiency, so we surface them separately rather
|
|
6126
|
-
# than summing into a single "cached" number that conflates the two.
|
|
6127
|
-
# Each clause is shown only when nonzero, so quiet sessions stay quiet.
|
|
6128
|
-
tokens_clause=""
|
|
6129
|
-
if [[ "$tot_in" -gt 0 || "$tot_out" -gt 0 || "$tot_cache_read" -gt 0 || "$tot_cache_write" -gt 0 ]]; then
|
|
6130
|
-
tokens_clause=" · $(fmt_tok "$tot_in") in / $(fmt_tok "$tot_out") out"
|
|
6131
|
-
if [[ "$tot_cache_read" -gt 0 ]]; then
|
|
6132
|
-
tokens_clause+=" / $(fmt_tok "$tot_cache_read") cache read"
|
|
6133
|
-
fi
|
|
6134
|
-
if [[ "$tot_cache_write" -gt 0 ]]; then
|
|
6135
|
-
tokens_clause+=" / $(fmt_tok "$tot_cache_write") cache write"
|
|
6136
|
-
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"
|
|
6137
6146
|
fi
|
|
6138
|
-
|
|
6139
|
-
|
|
6140
|
-
|
|
6141
|
-
|
|
6142
|
-
|
|
6143
|
-
|
|
6144
|
-
|
|
6145
|
-
printf '
|
|
6146
|
-
elif [[ "$routed" == "failure" ]]; then
|
|
6147
|
-
# Latest turn was a CC-synthesized error stub — don't claim a routing
|
|
6148
|
-
# swap or compute savings against a non-model.
|
|
6149
|
-
printf '%s — %s%s' "$brand" "$routed" "$tokens_clause"
|
|
6150
|
-
elif [[ -n "$routed" ]]; then
|
|
6151
|
-
# Always show the savings clause, flooring a non-positive total at $0.00.
|
|
6152
|
-
# session_savings is "0.0000" on fresh sessions or sessions where every
|
|
6153
|
-
# turn routed back to the selected model, and can go negative when routing
|
|
6154
|
-
# upgrades a turn to a pricier model (e.g. a sticky/hard-pinned side-call,
|
|
6155
|
-
# or a hard turn escalated to opus). "saved -$X" would mislead, so clamp
|
|
6156
|
-
# the display to $0.00 rather than dropping the clause — a $0.00 readout
|
|
6157
|
-
# tells the user the router ran and simply didn't beat their selection.
|
|
6158
|
-
# When the CC selection is unknown ("?" or empty) there's nothing to
|
|
6159
|
-
# compare against, so drop the "← selection" arrow and just show routed.
|
|
6160
|
-
display_savings="$session_savings"
|
|
6161
|
-
if [[ -z "$display_savings" ]] \
|
|
6162
|
-
|| awk -v v="$display_savings" 'BEGIN{exit !(v+0 < 0)}'; then
|
|
6163
|
-
display_savings="0"
|
|
6164
|
-
fi
|
|
6165
|
-
if [[ -n "$selected_display" && "$selected_display" != "?" ]]; then
|
|
6166
|
-
printf '%s — %s ← %s · saved %s%s' \
|
|
6167
|
-
"$brand" "$routed" "$selected_display" "$(fmt_money "$display_savings")" "$tokens_clause"
|
|
6168
|
-
else
|
|
6169
|
-
printf '%s — %s%s' "$brand" "$routed" "$tokens_clause"
|
|
6170
|
-
fi
|
|
6171
|
-
else
|
|
6172
|
-
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"
|
|
6173
6155
|
fi
|
|
6174
6156
|
STATUSLINE_EOF
|
|
6175
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 },
|