@weave-os/router 0.2.29 → 0.2.30
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 +20 -16
- package/bin.js +53 -10
- package/cc-statusline.sh +269 -56
- package/codex-skills/force-parent/SKILL.md +23 -0
- package/codex-skills/force-parent/scripts/emit.sh +7 -0
- package/codex-skills/router-models/SKILL.md +1 -1
- package/codex-status.sh +312 -48
- package/codex-toggle.sh +1 -1
- package/commands/force-parent.md +6 -0
- package/commands/models.md +1 -1
- package/commands/router-models.md +1 -1
- package/directives.tsv +1 -0
- package/install.sh +1566 -218
- package/package.json +8 -2
- package/pi-router/README.md +4 -2
- package/pi-router/src/force-model.ts +109 -38
- package/pi-router/src/pricing.generated.ts +8 -3
- package/pi-router/src/routed-model.ts +51 -7
- package/pi-router/src/ui.ts +3 -3
- package/uninstall.sh +167 -9
- package/windows.js +545 -0
package/cc-statusline.sh
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
# { "statusLine": { "type": "command", "command": "/abs/path/to/cc-statusline.sh" } }
|
|
11
11
|
#
|
|
12
12
|
# Renders:
|
|
13
|
-
# WEAVE ROUTER ·
|
|
13
|
+
# WEAVE ROUTER · you picked opus-4-7 → served sonnet-4-5 · saved ~$1.23 this session
|
|
14
14
|
#
|
|
15
15
|
# Pricing source of truth: internal/router/catalog. Input/output prices and
|
|
16
16
|
# cache-read multipliers are generated by cmd/genprices. Cache creation remains
|
|
@@ -19,6 +19,48 @@
|
|
|
19
19
|
set -euo pipefail
|
|
20
20
|
export PATH="$PATH:$HOME/.weave/bin"
|
|
21
21
|
|
|
22
|
+
# ---------- /router-status prompt hook ----------
|
|
23
|
+
#
|
|
24
|
+
# Registered as a UserPromptSubmit hook with --prompt-hook. Every other prompt
|
|
25
|
+
# passes through untouched; /router-status is answered from local state and
|
|
26
|
+
# stopped before it reaches a model, so checking the router never spends a
|
|
27
|
+
# turn. The settings env (router URL and key header) is inherited by hooks, and
|
|
28
|
+
# the session's last statusline render is cached by the statusline below.
|
|
29
|
+
weave_router_status_hook() {
|
|
30
|
+
command -v jq >/dev/null 2>&1 || return 0
|
|
31
|
+
local payload prompt session line="" root report scope_suffix=""
|
|
32
|
+
[ "$#" -eq 0 ] || scope_suffix="$(printf ' %q' "$@")"
|
|
33
|
+
payload="$(cat)"
|
|
34
|
+
prompt="$(jq -r '.prompt // empty' <<<"$payload" 2>/dev/null)" || return 0
|
|
35
|
+
[[ "$prompt" =~ ^[[:space:]]*/router-status[[:space:]]*$ ]] || return 0
|
|
36
|
+
if [[ "${ANTHROPIC_BASE_URL:-}" == https://api.anthropic.com* ]]; then
|
|
37
|
+
report="Weave Router is off: Claude Code talks to Anthropic directly. Turn it back on with /router-on."
|
|
38
|
+
elif [[ -n "${ANTHROPIC_BASE_URL:-}" && "${ANTHROPIC_CUSTOM_HEADERS:-}" == *"X-Weave-Router-Key:"* ]]; then
|
|
39
|
+
report="Weave Router is on: Claude Code sends requests to ${ANTHROPIC_BASE_URL}."
|
|
40
|
+
elif [[ -n "${ANTHROPIC_BASE_URL:-}" ]]; then
|
|
41
|
+
report="Claude Code sends requests to ${ANTHROPIC_BASE_URL}, but no Weave Router key is set. Repair it with: npx @weave-os/router update --claude${scope_suffix}"
|
|
42
|
+
else
|
|
43
|
+
report="Weave Router is off: Claude Code talks to Anthropic directly. Turn it back on with /router-on."
|
|
44
|
+
fi
|
|
45
|
+
session="$(jq -r '.session_id // empty' <<<"$payload" 2>/dev/null)" || session=""
|
|
46
|
+
root="${XDG_CACHE_HOME:-$HOME/.cache}/weave-router/claude-status"
|
|
47
|
+
if [[ "$session" =~ ^[A-Za-z0-9._-]{1,128}$ && -f "$root/$session.line" ]]; then
|
|
48
|
+
line="$(head -c 512 "$root/$session.line" | head -n 1)"
|
|
49
|
+
fi
|
|
50
|
+
if [[ -n "$line" ]]; then
|
|
51
|
+
report="$report"$'\n'"This session: $line"
|
|
52
|
+
else
|
|
53
|
+
report="$report"$'\n'"No routed turn yet in this session."
|
|
54
|
+
fi
|
|
55
|
+
report="$report"$'\n'"Full check (key, login, endpoint): npx @weave-os/router status --claude${scope_suffix}"
|
|
56
|
+
jq -n --arg reason "$report" '{continue: false, stopReason: $reason, suppressOutput: true}'
|
|
57
|
+
}
|
|
58
|
+
if [ "${1:-}" = "--prompt-hook" ]; then
|
|
59
|
+
shift
|
|
60
|
+
weave_router_status_hook "$@" || true
|
|
61
|
+
exit 0
|
|
62
|
+
fi
|
|
63
|
+
|
|
22
64
|
# ---------- background self-refresh ----------
|
|
23
65
|
#
|
|
24
66
|
# Once every WEAVE_STATUSLINE_UPDATE_INTERVAL_DAYS (default 7), check
|
|
@@ -419,7 +461,14 @@ weave_hidden_gate() {
|
|
|
419
461
|
file://*) ;;
|
|
420
462
|
*) url="$url/v1/display-settings" ;;
|
|
421
463
|
esac
|
|
422
|
-
|
|
464
|
+
header_file="$(mktemp "$cache_dir/.headers.XXXXXX")" || exit 0
|
|
465
|
+
chmod 600 "$header_file"
|
|
466
|
+
printf 'header = "X-Weave-Router-Key: %s"\n' "$key" >"$header_file"
|
|
467
|
+
if ! body="$(curl -fsS --max-time 5 -K "$header_file" "$url" 2>/dev/null)"; then
|
|
468
|
+
rm -f "$header_file"
|
|
469
|
+
exit 0
|
|
470
|
+
fi
|
|
471
|
+
rm -f "$header_file"
|
|
423
472
|
hidden="$(printf '%s' "$body" | jq -r '.hide_terminal_surfaces // false' 2>/dev/null)"
|
|
424
473
|
tmp="$cache.tmp.$$"
|
|
425
474
|
if [ "$hidden" = "true" ]; then
|
|
@@ -438,6 +487,7 @@ if weave_hidden_gate </dev/null; then
|
|
|
438
487
|
fi
|
|
439
488
|
|
|
440
489
|
input="$(cat)"
|
|
490
|
+
jq -e 'type == "object"' >/dev/null 2>&1 <<<"$input" || exit 0
|
|
441
491
|
transcript_path="$(printf '%s' "$input" | jq -r '.transcript_path // empty')"
|
|
442
492
|
# Prefer model.id over display_name: pricing keys + the response model id in
|
|
443
493
|
# the transcript are canonical ids (e.g. claude-opus-4-7), while display_name
|
|
@@ -445,6 +495,19 @@ transcript_path="$(printf '%s' "$input" | jq -r '.transcript_path // empty')"
|
|
|
445
495
|
# preventing a price comparison. id passes through normalize_model cleanly.
|
|
446
496
|
selected_display="$(printf '%s' "$input" | jq -r '.model.id // .model.display_name // "?"')"
|
|
447
497
|
|
|
498
|
+
# Claude owns this percentage and its window; session totals never establish it.
|
|
499
|
+
context_clause="$(jq -r '
|
|
500
|
+
.context_window as $c |
|
|
501
|
+
if ($c.context_window_size | type) == "number" and $c.context_window_size > 0 and $c.context_window_size <= 2147483647
|
|
502
|
+
and ($c.context_window_size | floor) == $c.context_window_size
|
|
503
|
+
and ($c.used_percentage | type) == "number" and $c.used_percentage >= 0 and $c.used_percentage <= 100
|
|
504
|
+
then " · Context " + ($c.used_percentage | floor | tostring) + "%" +
|
|
505
|
+
(if $c.used_percentage >= 90 then " !" else "" end)
|
|
506
|
+
else "" end
|
|
507
|
+
' <<<"$input" 2>/dev/null)" || context_clause=""
|
|
508
|
+
|
|
509
|
+
[ "${WEAVE_STATUSLINE_CONTEXT:-1}" != "0" ] || context_clause=""
|
|
510
|
+
|
|
448
511
|
# Normalize a model id to a pricing-table key. CC + the decisions log carry
|
|
449
512
|
# two flavors of annotation we don't want in the lookup:
|
|
450
513
|
# * date suffix: claude-opus-4-7-20260101 → claude-opus-4-7
|
|
@@ -463,6 +526,7 @@ prices='{
|
|
|
463
526
|
"claude-fable-5": 0.01,
|
|
464
527
|
"claude-fable-5-1": 0.01,
|
|
465
528
|
"claude-haiku-4-5": 0.001,
|
|
529
|
+
"claude-haiku-5-5": 0.0001,
|
|
466
530
|
"claude-opus-4-0": 0.015,
|
|
467
531
|
"claude-opus-4-1": 0.015,
|
|
468
532
|
"claude-opus-4-5": 0.005,
|
|
@@ -473,7 +537,7 @@ prices='{
|
|
|
473
537
|
"claude-opus-5-5": 0.004,
|
|
474
538
|
"claude-sonnet-4-5": 0.003,
|
|
475
539
|
"claude-sonnet-4-6": 0.003,
|
|
476
|
-
"claude-sonnet-5": 0.
|
|
540
|
+
"claude-sonnet-5": 0.002,
|
|
477
541
|
"claude-sonnet-5-5": 0.002,
|
|
478
542
|
"deepseek/deepseek-v4-flash": 0.00014,
|
|
479
543
|
"deepseek/deepseek-v4-pro": 0.00174,
|
|
@@ -493,6 +557,7 @@ prices='{
|
|
|
493
557
|
"gemini-3.6-flash": 0.0015,
|
|
494
558
|
"gemini-3.7-flash": 0.0015,
|
|
495
559
|
"gemini-3.8-flash": 0.0015,
|
|
560
|
+
"gemini-4-argon": 0.002,
|
|
496
561
|
"google/gemma-4-26b-a4b-it": 0.00015,
|
|
497
562
|
"gpt-4.1": 0.002,
|
|
498
563
|
"gpt-4.1-mini": 0.0004,
|
|
@@ -520,17 +585,20 @@ prices='{
|
|
|
520
585
|
"gpt-6-luna": 0.0001,
|
|
521
586
|
"gpt-6-sol": 0.002,
|
|
522
587
|
"gpt-6.1-sol": 0.002,
|
|
588
|
+
"gpt-6.1-terra": 0.001,
|
|
523
589
|
"grok-4.5": 0.002,
|
|
524
590
|
"grok-4.6": 0.002,
|
|
525
591
|
"grok-4.7": 0.002,
|
|
526
592
|
"inclusionai/ling-3.0-flash": 0.00006,
|
|
527
593
|
"minimax/minimax-m2.7": 0.0003,
|
|
528
594
|
"minimax/minimax-m3": 0.0003,
|
|
595
|
+
"minimax/minimax-m3.1-flash": 0.00015,
|
|
529
596
|
"mistralai/mistral-small-2603": 0.0002,
|
|
530
597
|
"moonshotai/kimi-k2.5": 0.0006,
|
|
531
598
|
"moonshotai/kimi-k2.6": 0.00095,
|
|
532
599
|
"moonshotai/kimi-k2.7": 0.00095,
|
|
533
600
|
"moonshotai/kimi-k3": 0.003,
|
|
601
|
+
"moonshotai/kimi-k3.1": 0.002,
|
|
534
602
|
"muse-spark-1.3": 0.00125,
|
|
535
603
|
"qwen/qwen3-235b-a22b-2507": 0.0002266,
|
|
536
604
|
"qwen/qwen3-30b-a3b-instruct-2507": 0.00015,
|
|
@@ -542,7 +610,7 @@ prices='{
|
|
|
542
610
|
"qwen/qwen3.7-plus": 0.0004,
|
|
543
611
|
"qwen/qwen3.8-max": 0.002,
|
|
544
612
|
"xiaomi/mimo-v2.5-pro": 0.001,
|
|
545
|
-
"xiaomi/mimo-v2.6-flash": 0.
|
|
613
|
+
"xiaomi/mimo-v2.6-flash": 0.00013,
|
|
546
614
|
"xiaomi/mimo-v2.6-pro": 0.000435,
|
|
547
615
|
"z-ai/glm-5": 0.001,
|
|
548
616
|
"z-ai/glm-5.1": 0.0014,
|
|
@@ -554,6 +622,7 @@ prices='{
|
|
|
554
622
|
"claude-fable-5": 0.05,
|
|
555
623
|
"claude-fable-5-1": 0.05,
|
|
556
624
|
"claude-haiku-4-5": 0.005,
|
|
625
|
+
"claude-haiku-5-5": 0.0005,
|
|
557
626
|
"claude-opus-4-0": 0.075,
|
|
558
627
|
"claude-opus-4-1": 0.075,
|
|
559
628
|
"claude-opus-4-5": 0.025,
|
|
@@ -564,7 +633,7 @@ prices='{
|
|
|
564
633
|
"claude-opus-5-5": 0.02,
|
|
565
634
|
"claude-sonnet-4-5": 0.015,
|
|
566
635
|
"claude-sonnet-4-6": 0.015,
|
|
567
|
-
"claude-sonnet-5": 0.
|
|
636
|
+
"claude-sonnet-5": 0.01,
|
|
568
637
|
"claude-sonnet-5-5": 0.01,
|
|
569
638
|
"deepseek/deepseek-v4-flash": 0.00028,
|
|
570
639
|
"deepseek/deepseek-v4-pro": 0.00348,
|
|
@@ -584,6 +653,7 @@ prices='{
|
|
|
584
653
|
"gemini-3.6-flash": 0.0075,
|
|
585
654
|
"gemini-3.7-flash": 0.0075,
|
|
586
655
|
"gemini-3.8-flash": 0.0075,
|
|
656
|
+
"gemini-4-argon": 0.01,
|
|
587
657
|
"google/gemma-4-26b-a4b-it": 0.0006,
|
|
588
658
|
"gpt-4.1": 0.008,
|
|
589
659
|
"gpt-4.1-mini": 0.0016,
|
|
@@ -611,17 +681,20 @@ prices='{
|
|
|
611
681
|
"gpt-6-luna": 0.0005,
|
|
612
682
|
"gpt-6-sol": 0.01,
|
|
613
683
|
"gpt-6.1-sol": 0.01,
|
|
684
|
+
"gpt-6.1-terra": 0.005,
|
|
614
685
|
"grok-4.5": 0.006,
|
|
615
686
|
"grok-4.6": 0.006,
|
|
616
687
|
"grok-4.7": 0.006,
|
|
617
688
|
"inclusionai/ling-3.0-flash": 0.00018,
|
|
618
689
|
"minimax/minimax-m2.7": 0.0012,
|
|
619
690
|
"minimax/minimax-m3": 0.0012,
|
|
691
|
+
"minimax/minimax-m3.1-flash": 0.0006,
|
|
620
692
|
"mistralai/mistral-small-2603": 0.0006,
|
|
621
693
|
"moonshotai/kimi-k2.5": 0.003,
|
|
622
694
|
"moonshotai/kimi-k2.6": 0.004,
|
|
623
695
|
"moonshotai/kimi-k2.7": 0.004,
|
|
624
696
|
"moonshotai/kimi-k3": 0.015,
|
|
697
|
+
"moonshotai/kimi-k3.1": 0.01,
|
|
625
698
|
"muse-spark-1.3": 0.00425,
|
|
626
699
|
"qwen/qwen3-235b-a22b-2507": 0.0009064,
|
|
627
700
|
"qwen/qwen3-30b-a3b-instruct-2507": 0.0006,
|
|
@@ -645,6 +718,7 @@ prices='{
|
|
|
645
718
|
"claude-fable-5": 0.1,
|
|
646
719
|
"claude-fable-5-1": 0.025,
|
|
647
720
|
"claude-haiku-4-5": 0.1,
|
|
721
|
+
"claude-haiku-5-5": 0.1,
|
|
648
722
|
"claude-opus-4-0": 0.1,
|
|
649
723
|
"claude-opus-4-1": 0.1,
|
|
650
724
|
"claude-opus-4-5": 0.1,
|
|
@@ -675,6 +749,7 @@ prices='{
|
|
|
675
749
|
"gemini-3.6-flash": 0.1,
|
|
676
750
|
"gemini-3.7-flash": 0.1,
|
|
677
751
|
"gemini-3.8-flash": 0.1,
|
|
752
|
+
"gemini-4-argon": 0.1,
|
|
678
753
|
"google/gemma-4-26b-a4b-it": 0.1,
|
|
679
754
|
"gpt-4.1": 0.25,
|
|
680
755
|
"gpt-4.1-mini": 0.25,
|
|
@@ -702,17 +777,20 @@ prices='{
|
|
|
702
777
|
"gpt-6-luna": 0.1,
|
|
703
778
|
"gpt-6-sol": 0.1,
|
|
704
779
|
"gpt-6.1-sol": 0.05,
|
|
780
|
+
"gpt-6.1-terra": 0.05,
|
|
705
781
|
"grok-4.5": 0.25,
|
|
706
782
|
"grok-4.6": 0.25,
|
|
707
783
|
"grok-4.7": 0.25,
|
|
708
784
|
"inclusionai/ling-3.0-flash": 0.2,
|
|
709
785
|
"minimax/minimax-m2.7": 0.2,
|
|
710
786
|
"minimax/minimax-m3": 0.2,
|
|
787
|
+
"minimax/minimax-m3.1-flash": 0.1,
|
|
711
788
|
"mistralai/mistral-small-2603": 0.1,
|
|
712
789
|
"moonshotai/kimi-k2.5": 0.5,
|
|
713
790
|
"moonshotai/kimi-k2.6": 0.1684,
|
|
714
791
|
"moonshotai/kimi-k2.7": 0.2,
|
|
715
792
|
"moonshotai/kimi-k3": 0.1,
|
|
793
|
+
"moonshotai/kimi-k3.1": 0.1,
|
|
716
794
|
"muse-spark-1.3": 0.12,
|
|
717
795
|
"qwen/qwen3-235b-a22b-2507": 0.5,
|
|
718
796
|
"qwen/qwen3-30b-a3b-instruct-2507": 0.1684,
|
|
@@ -724,7 +802,7 @@ prices='{
|
|
|
724
802
|
"qwen/qwen3.7-plus": 0.2,
|
|
725
803
|
"qwen/qwen3.8-max": 0.125,
|
|
726
804
|
"xiaomi/mimo-v2.5-pro": 0.1,
|
|
727
|
-
"xiaomi/mimo-v2.6-flash": 0.
|
|
805
|
+
"xiaomi/mimo-v2.6-flash": 0.015384615384615385,
|
|
728
806
|
"xiaomi/mimo-v2.6-pro": 0.00827586,
|
|
729
807
|
"z-ai/glm-5": 0.2,
|
|
730
808
|
"z-ai/glm-5.1": 0.18571428571428572,
|
|
@@ -765,38 +843,37 @@ if [[ -n "$transcript_path" && -f "$transcript_path" ]]; then
|
|
|
765
843
|
transcript_model="$(normalize_model "$transcript_model")"
|
|
766
844
|
fi
|
|
767
845
|
|
|
768
|
-
#
|
|
769
|
-
#
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
| grep -m1 -v '^REJECTED$' || true)"
|
|
846
|
+
# Fold acknowledged transitions in transcript order. Content-block copies and
|
|
847
|
+
# replayed outcome IDs are the same event, not a newer state change.
|
|
848
|
+
force_state="$(jq -nRr '
|
|
849
|
+
def model: type == "string" and test("^[A-Za-z0-9._:/-]{1,128}$");
|
|
850
|
+
def valid_command_outcome:
|
|
851
|
+
try (.version == 1 and (.id | type == "string" and test("^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$"))
|
|
852
|
+
and (.command | IN("force_model", "router_session", "router_models", "router_feedback", "loop_stop"))
|
|
853
|
+
and (.disposition | IN("accepted", "rejected"))
|
|
854
|
+
and (.pin.transition | IN("unchanged", "applied", "cleared"))
|
|
855
|
+
and (if .pin.transition == "unchanged" then true else
|
|
856
|
+
.command == "force_model" and .disposition == "accepted" end)
|
|
857
|
+
and (if .pin.transition == "applied" then (.pin.model | model)
|
|
858
|
+
and (.pin.provider | model)
|
|
859
|
+
and ((.pin.effort // "") | type == "string" and test("^[A-Za-z0-9_-]{0,32}$")) else true end)) catch false;
|
|
860
|
+
reduce (inputs | fromjson? | objects) as $entry ({seen:{}, pin:null};
|
|
861
|
+
if $entry.type != "assistant" or $entry.message.model != "weave-router" then .
|
|
862
|
+
elif ($entry.message | has("router_command")) then
|
|
863
|
+
$entry.message.router_command as $o |
|
|
864
|
+
if ($o | valid_command_outcome) and (.seen[$o.id] != true) then
|
|
865
|
+
.seen[$o.id] = true |
|
|
866
|
+
if $o.pin.transition == "applied" then
|
|
867
|
+
.pin = ($o.pin.model + (if ($o.pin.effort // "") == "" then "" else ":" + $o.pin.effort end))
|
|
868
|
+
elif $o.pin.transition == "cleared" then .pin = null else . end
|
|
869
|
+
else . end
|
|
870
|
+
else
|
|
871
|
+
([$entry.message.content[]? | select(.type? == "text") | .text] | join(" ") | sub("^(?:✦ \\*\\*Weave Router\\*\\* →|Weave Router:)[[:space:]]*"; "")) as $t |
|
|
872
|
+
if ($t | test("^force-(model|parent) applied: [A-Za-z0-9._:/-]+")) then
|
|
873
|
+
.pin = ($t | capture("force-(?:model|parent) applied: (?<m>[A-Za-z0-9._:/-]+)").m)
|
|
874
|
+
elif ($t | test("^force-model cleared\\b")) then .pin = null else . end
|
|
875
|
+
end) | if .pin then "APPLIED " + .pin else "CLEARED" end
|
|
876
|
+
' "$transcript_path" 2>/dev/null || true)"
|
|
800
877
|
if [[ "$force_state" == APPLIED\ * ]]; then
|
|
801
878
|
has_pin_record="true"
|
|
802
879
|
last_pin_model="${force_state#APPLIED }"
|
|
@@ -888,35 +965,171 @@ weave_refresh_on_price_miss() {
|
|
|
888
965
|
}
|
|
889
966
|
weave_refresh_on_price_miss "$requested_norm" "$transcript_model" 2>/dev/null || true
|
|
890
967
|
|
|
968
|
+
router_context_fallback() {
|
|
969
|
+
[ -z "$context_clause" ] || return 0
|
|
970
|
+
[ "${WEAVE_STATUSLINE_CONTEXT:-1}" != "0" ] || return 0
|
|
971
|
+
local session helper_dir scope cache root now snapshot
|
|
972
|
+
session="$(jq -r '.session_id // empty' <<<"$input")"
|
|
973
|
+
case "$session" in ''|*[!A-Za-z0-9._-]*) return 0 ;; esac
|
|
974
|
+
[ "${#session}" -le 128 ] || return 0
|
|
975
|
+
helper_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)"
|
|
976
|
+
scope="$(printf '%s' "$helper_dir" | cksum | awk '{print $1}')"
|
|
977
|
+
root="${XDG_CACHE_HOME:-$HOME/.cache}/weave-router/claude-context"
|
|
978
|
+
cache="$root/$scope-$session.json"
|
|
979
|
+
mkdir -p "$root" 2>/dev/null || return 0
|
|
980
|
+
chmod 700 "$root"
|
|
981
|
+
local generation active_file
|
|
982
|
+
active_file="$cache.active"
|
|
983
|
+
now="$(date +%s)"
|
|
984
|
+
if [ -f "$cache" ] && [ "$(wc -c <"$cache")" -le 8192 ]; then
|
|
985
|
+
snapshot="$(jq -ce --arg session "$session" --argjson now "$now" '
|
|
986
|
+
|
|
987
|
+
def tokens: type == "number" and floor == . and . > 0 and . <= 2147483647;
|
|
988
|
+
def epoch: sub("\\.[0-9]+Z$"; "Z") | fromdateiso8601;
|
|
989
|
+
.context_snapshot as $s |
|
|
990
|
+
select(.session_id == $session and $s.version == 1 and $s.estimate_kind == "approximate") |
|
|
991
|
+
select(($s.estimate_tokens | tokens) and ($s.context_window | tokens) and ($s.output_reserve_tokens | tokens)) |
|
|
992
|
+
select(($s.served_model | type) == "string" and ($s.served_model | test("^[A-Za-z0-9._:/-]{1,128}$"))) |
|
|
993
|
+
select(($s.request_id | type) == "string" and ($s.request_id | length) > 0 and ($s.request_id | length) <= 128) |
|
|
994
|
+
($s.recorded_at | epoch) as $recorded | ($s.requested_at | epoch) as $requested |
|
|
995
|
+
select($requested > 0 and $requested <= $recorded and $recorded <= $now and $now - $recorded <= 300) |
|
|
996
|
+
$s
|
|
997
|
+
' "$cache" 2>/dev/null)" || snapshot=""
|
|
998
|
+
if [ -n "$snapshot" ]; then
|
|
999
|
+
local served requested
|
|
1000
|
+
served="$(normalize_model "$(jq -r '.served_model' <<<"$snapshot")")"
|
|
1001
|
+
requested="$(normalize_model "$(jq -r '.requested_model // empty' <<<"$snapshot")")"
|
|
1002
|
+
if [ "$served" = "$transcript_model" ] && [ "$requested" = "$requested_norm" ]; then
|
|
1003
|
+
context_clause="$(awk -v e="$(jq -r '.estimate_tokens' <<<"$snapshot")" -v w="$(jq -r '.context_window' <<<"$snapshot")" 'BEGIN {
|
|
1004
|
+
printf " · last Router ctx est. ~%s/%s", (e < 1000 ? e : sprintf("%.0fk", e/1000)), (w < 1000 ? w : sprintf("%.0fk", w/1000))
|
|
1005
|
+
}')"
|
|
1006
|
+
fi
|
|
1007
|
+
fi
|
|
1008
|
+
fi
|
|
1009
|
+
command -v curl >/dev/null 2>&1 || return 0
|
|
1010
|
+
mkdir -p "$root" 2>/dev/null || return 0
|
|
1011
|
+
chmod 700 "$root"
|
|
1012
|
+
(
|
|
1013
|
+
exec </dev/null
|
|
1014
|
+
# Serialize refreshes; a timeout cannot delay the status-line process.
|
|
1015
|
+
if ! mkdir "$cache.lock" 2>/dev/null; then
|
|
1016
|
+
lock_mtime="$(stat -c %Y "$cache.lock" 2>/dev/null || stat -f %m "$cache.lock" 2>/dev/null)" || lock_mtime=0
|
|
1017
|
+
[ $(( $(date +%s) - lock_mtime )) -gt 30 ] || exit 0
|
|
1018
|
+
dead="$cache.lock.dead.$$"
|
|
1019
|
+
mv "$cache.lock" "$dead" 2>/dev/null || exit 0
|
|
1020
|
+
rm -rf "$dead"
|
|
1021
|
+
mkdir "$cache.lock" 2>/dev/null || exit 0
|
|
1022
|
+
fi
|
|
1023
|
+
trap 'rmdir "$cache.lock" 2>/dev/null' EXIT
|
|
1024
|
+
generation="$(mktemp "$root/.generation.XXXXXX")" || exit 0
|
|
1025
|
+
printf '%s' "$generation" >"$generation"
|
|
1026
|
+
chmod 600 "$generation"
|
|
1027
|
+
mv "$generation" "$active_file"
|
|
1028
|
+
settings_base="$HOME"
|
|
1029
|
+
case "$helper_dir" in */.claude) settings_base="${helper_dir%/.claude}" ;; esac
|
|
1030
|
+
settings="$settings_base/.claude/settings.json"
|
|
1031
|
+
local_settings="$settings_base/.claude/settings.local.json"
|
|
1032
|
+
base=""
|
|
1033
|
+
key=""
|
|
1034
|
+
for settings_file in "$settings" "$local_settings"; do
|
|
1035
|
+
[ -f "$settings_file" ] || continue
|
|
1036
|
+
if jq -e '.env | has("ANTHROPIC_BASE_URL")' "$settings_file" >/dev/null 2>&1; then
|
|
1037
|
+
base="$(jq -r '.env.ANTHROPIC_BASE_URL // empty' "$settings_file" 2>/dev/null)"
|
|
1038
|
+
fi
|
|
1039
|
+
if jq -e '.env | has("ANTHROPIC_CUSTOM_HEADERS")' "$settings_file" >/dev/null 2>&1; then
|
|
1040
|
+
key="$(jq -r '.env.ANTHROPIC_CUSTOM_HEADERS // "" | split("\n")[] | select(startswith("X-Weave-Router-Key:")) | sub("^X-Weave-Router-Key:[[:space:]]*"; "")' "$settings_file" 2>/dev/null | head -n1)"
|
|
1041
|
+
fi
|
|
1042
|
+
done
|
|
1043
|
+
base="${WEAVE_ROUTER_BASE_URL:-${ANTHROPIC_BASE_URL:-$base}}"
|
|
1044
|
+
key="${WEAVE_ROUTER_KEY:-$key}"
|
|
1045
|
+
[ -n "$base" ] && [ -n "$key" ] || exit 0
|
|
1046
|
+
url="${base%/}"
|
|
1047
|
+
case "$url" in file://*) ;; *) url="${url%/v1}/v1/sessions/$session/cost" ;; esac
|
|
1048
|
+
tmp="$(mktemp "$root/.snapshot.XXXXXX")" || exit 0
|
|
1049
|
+
header_file="$(mktemp "$root/.headers.XXXXXX")" || { rm -f "$tmp"; exit 0; }
|
|
1050
|
+
chmod 600 "$tmp"
|
|
1051
|
+
chmod 600 "$header_file"
|
|
1052
|
+
printf 'header = "X-Weave-Router-Key: %s"\n' "$key" >"$header_file"
|
|
1053
|
+
if curl -fsS --max-time 5 --max-filesize 8192 -K "$header_file" "$url" -o "$tmp" 2>/dev/null \
|
|
1054
|
+
&& [ "$(wc -c <"$tmp")" -le 8192 ] \
|
|
1055
|
+
&& [ "$(jq -r '.session_id // empty' "$tmp" 2>/dev/null)" = "$session" ]; then
|
|
1056
|
+
# Request observation order is independent of fetch completion order.
|
|
1057
|
+
# Fraction padding preserves RFC3339Nano order within the same second.
|
|
1058
|
+
previous="$cache"
|
|
1059
|
+
[ -f "$previous" ] || previous=/dev/null
|
|
1060
|
+
if [ "$(cat "$active_file" 2>/dev/null)" = "$generation" ] && jq -e -s '
|
|
1061
|
+
def timestamp_parts: split(".") as $p |
|
|
1062
|
+
[($p[0] | sub("Z$"; "")), ((($p[1] // "") | sub("Z$"; "")) + "000000000")[0:9]];
|
|
1063
|
+
def observation: [.context_snapshot.requested_at | timestamp_parts] + [.context_snapshot.recorded_at | timestamp_parts];
|
|
1064
|
+
(.[0] | observation) as $fresh |
|
|
1065
|
+
if length == 1 or .[1].context_snapshot == null then true else $fresh > (.[1] | observation) or ($fresh == (.[1] | observation) and .[0].context_snapshot.request_id == .[1].context_snapshot.request_id) end
|
|
1066
|
+
' "$tmp" "$previous" 2>/dev/null; then
|
|
1067
|
+
mv "$tmp" "$cache"
|
|
1068
|
+
fi
|
|
1069
|
+
fi
|
|
1070
|
+
rm -f "$tmp" "$header_file"
|
|
1071
|
+
) >/dev/null 2>&1 &
|
|
1072
|
+
disown 2>/dev/null || true
|
|
1073
|
+
}
|
|
1074
|
+
router_context_fallback 2>/dev/null || true
|
|
1075
|
+
|
|
891
1076
|
# Brand color (#FF6C47) on terminals that grok 24-bit truecolor — that's
|
|
892
1077
|
# every modern one (iTerm2, Apple Terminal, vscode, ghostty, alacritty,
|
|
893
1078
|
# wezterm, kitty). Falls back gracefully on any escape-stripping terminal.
|
|
894
1079
|
brand=$'\033[38;2;255;108;71mWEAVE ROUTER\033[0m'
|
|
895
1080
|
|
|
896
|
-
# Format helpers.
|
|
897
|
-
fmt_money() {
|
|
898
|
-
awk -v v="$1" 'BEGIN{
|
|
899
|
-
if (v == "" || v+0 == 0) { printf "$0.00"; exit }
|
|
900
|
-
if (v+0 < 0.005 && v+0 > -0.005){ printf "%s<$0.01", (v+0 < 0 ? "-" : ""); exit }
|
|
901
|
-
if (v+0 < 0) { printf "-$%.2f", -v+0; exit }
|
|
902
|
-
printf "$%.2f", v
|
|
903
|
-
}'
|
|
904
|
-
}
|
|
905
1081
|
|
|
906
|
-
|
|
1082
|
+
# "you picked" is Claude Code's selection; "served" is the latest response
|
|
1083
|
+
# model in the transcript. The cost clause is the whole session priced at the
|
|
1084
|
+
# served models versus the pick, so an upgrade reads as "more", not a negative
|
|
1085
|
+
# saving.
|
|
1086
|
+
short_model() { printf '%s' "${1#claude-}"; }
|
|
1087
|
+
picked=""
|
|
1088
|
+
if [[ -n "$selected_display" && "$selected_display" != "?" ]]; then
|
|
1089
|
+
picked="$(short_model "$requested_norm")"
|
|
1090
|
+
fi
|
|
1091
|
+
status_text=""
|
|
907
1092
|
if [[ "$transcript_model" == "failure" ]]; then
|
|
908
|
-
|
|
1093
|
+
status_text=" · last response failed"
|
|
909
1094
|
elif [[ "$transcript_model" == "weave-router" ]]; then
|
|
910
|
-
|
|
1095
|
+
status_text=" · control acknowledgement"
|
|
911
1096
|
elif [[ -n "$transcript_model" ]]; then
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
1097
|
+
if [[ -n "$picked" && "$transcript_model" != "$requested_norm" ]]; then
|
|
1098
|
+
status_text=" · you picked $picked → served $(short_model "$transcript_model")"
|
|
1099
|
+
else
|
|
1100
|
+
status_text=" · served $(short_model "$transcript_model")"
|
|
1101
|
+
fi
|
|
1102
|
+
elif [[ -n "$picked" ]]; then
|
|
1103
|
+
status_text=" · you picked $picked"
|
|
916
1104
|
fi
|
|
917
1105
|
if [[ -n "$session_cost_difference" && "$session_cost_difference" != "unknown" && "$transcript_model" != "failure" && "$transcript_model" != "weave-router" ]]; then
|
|
918
|
-
|
|
1106
|
+
status_text="$status_text$(awk -v v="$session_cost_difference" -v pick="$picked" 'BEGIN{
|
|
1107
|
+
v = v + 0
|
|
1108
|
+
if (v >= 0.005) printf " · saved ~$%.2f this session", v
|
|
1109
|
+
else if (v > 0) printf " · saved <$0.01 this session"
|
|
1110
|
+
else if (v == 0) printf " · no savings yet this session"
|
|
1111
|
+
else if (v > -0.005) printf " · cost <$0.01 more than %s this session", pick
|
|
1112
|
+
else printf " · cost ~$%.2f more than %s this session (upgraded hard turns)", -v, pick
|
|
1113
|
+
}')"
|
|
919
1114
|
fi
|
|
920
1115
|
if [[ "$has_pin_record" == "true" ]]; then
|
|
921
|
-
|
|
1116
|
+
status_text="$status_text · last pin: $last_pin_model"
|
|
922
1117
|
fi
|
|
1118
|
+
|
|
1119
|
+
# /router-status reads this back through the prompt hook, so it can answer
|
|
1120
|
+
# without a model turn.
|
|
1121
|
+
weave_cache_status_line() {
|
|
1122
|
+
local session root
|
|
1123
|
+
session="$(jq -r '.session_id // empty' <<<"$input")"
|
|
1124
|
+
case "$session" in ''|*[!A-Za-z0-9._-]*) return 0 ;; esac
|
|
1125
|
+
[ "${#session}" -le 128 ] || return 0
|
|
1126
|
+
[ -n "$transcript_model" ] || return 0
|
|
1127
|
+
root="${XDG_CACHE_HOME:-$HOME/.cache}/weave-router/claude-status"
|
|
1128
|
+
mkdir -p "$root" && chmod 700 "$root" || return 0
|
|
1129
|
+
printf '%s\n' "${status_text# · }" >"$root/$session.line.$$" \
|
|
1130
|
+
&& mv -f "$root/$session.line.$$" "$root/$session.line"
|
|
1131
|
+
}
|
|
1132
|
+
weave_cache_status_line 2>/dev/null || true
|
|
1133
|
+
|
|
1134
|
+
printf '%s%s' "$brand" "$status_text"
|
|
1135
|
+
printf '%s' "$context_clause"
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: force-parent
|
|
3
|
+
description: "Pin the current parent thread to a model through the Weave Router while subagents route automatically."
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
<!-- weave-router managed force-parent skill -->
|
|
7
|
+
|
|
8
|
+
When the user requests `$force-parent <model-id>[:effort]`, run this skill's
|
|
9
|
+
`scripts/emit.sh` using the absolute path of this skill directory. Pass the
|
|
10
|
+
model and optional effort as one quoted argument. If no model was supplied,
|
|
11
|
+
ask which model to pin.
|
|
12
|
+
|
|
13
|
+
The script prints a leading-space `/force-parent` directive. The Weave Router
|
|
14
|
+
reads that exec output and pins only the invoking thread, then continues this
|
|
15
|
+
turn. Run it once, do not repeat its output as a user message, and report the
|
|
16
|
+
router's response. The directive requires a router version supporting
|
|
17
|
+
`force-parent`; do not claim success without its acknowledgment.
|
|
18
|
+
|
|
19
|
+
`$force-parent` replaces any conversation-wide `$force-model` pin. Children
|
|
20
|
+
keep their normal routing policy. `$force-model` restores conversation-wide
|
|
21
|
+
pinning; `$unforce-model` clears either mode. Model aliases and `:effort`
|
|
22
|
+
suffixes follow `$force-model` syntax. A compaction that changes the thread's
|
|
23
|
+
first user message changes its identity; reapply the pin in that thread.
|
|
@@ -43,7 +43,7 @@ Other things they might ask for:
|
|
|
43
43
|
|
|
44
44
|
If the command reports that this router doesn't expose model selection, that's a
|
|
45
45
|
Weave-hosted router: model selection belongs to the whole organization there, so
|
|
46
|
-
tell the user to change it at https://router.workweave.ai/
|
|
46
|
+
tell the user to change it at https://router.workweave.ai/models —
|
|
47
47
|
don't try to work around it. Its listing carries no on/off state, so present it
|
|
48
48
|
as a plain list; don't infer which models are enabled.
|
|
49
49
|
|