@weave-os/router 0.2.29 → 0.2.31

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/codex-status.sh CHANGED
@@ -93,6 +93,9 @@ weave_self_refresh() {
93
93
  return 0
94
94
  }
95
95
 
96
+ async_title_enabled=0
97
+ [ ! -t 2 ] || async_title_enabled=1
98
+
96
99
  state_root="${XDG_CACHE_HOME:-$HOME/.cache}/weave-router/codex"
97
100
  helper_dir="$(cd "$(dirname "$0")" 2>/dev/null && pwd -P)"
98
101
  disabled_marker="$helper_dir/.weave-router-disabled"
@@ -102,7 +105,7 @@ emit_title() {
102
105
  local title="$1"
103
106
  if [ -n "${WEAVE_CODEX_STATUS_TITLE_FILE:-}" ]; then
104
107
  printf '%s\n' "$title" >"$WEAVE_CODEX_STATUS_TITLE_FILE"
105
- elif [ -t 2 ] && [ -w /dev/tty ]; then
108
+ elif { [ -t 2 ] || [ "${async_title_enabled:-0}" = "1" ]; } && [ -w /dev/tty ]; then
106
109
  printf '\033]0;%s\007' "$title" >/dev/tty
107
110
  fi
108
111
  return 0
@@ -118,13 +121,14 @@ safe_session_id() {
118
121
  }
119
122
 
120
123
  safe_display_value() {
121
- printf '%s' "$1" | sed 's/[^A-Za-z0-9._:\/-]//g' | cut -c1-128
124
+ printf '%s' "$1" | sed 's/[^A-Za-z0-9._:\/-]//g' | cut -c1-64
122
125
  }
123
126
 
124
127
  state_file_for() {
125
- local id
128
+ local id scope
126
129
  id="$(safe_session_id "$1")" || return 1
127
- printf '%s/%s.state' "$state_root" "$id"
130
+ scope="$(printf '%s' "$helper_dir" | cksum | awk '{print $1}')"
131
+ printf '%s/%s-%s.state' "$state_root" "$scope" "$id"
128
132
  }
129
133
 
130
134
  read_state() {
@@ -133,6 +137,8 @@ read_state() {
133
137
  while IFS='=' read -r key value; do
134
138
  case "$key" in
135
139
  routed_model) routed_model="$value" ;;
140
+ last_pin_model) last_pin_model="$value" ;;
141
+ command_ids) command_ids="$value" ;;
136
142
  esac
137
143
  done <"$file"
138
144
  }
@@ -142,7 +148,7 @@ write_state() {
142
148
  mkdir -p "$state_root"
143
149
  chmod 700 "$state_root"
144
150
  tmp="$(mktemp "$state_root/.state.XXXXXX")"
145
- printf 'requested_model=%s\nrouted_model=%s\n' "$requested_model" "$routed_model" >"$tmp"
151
+ printf 'requested_model=%s\nrouted_model=%s\nlast_pin_model=%s\ncommand_ids=%s\n' "$requested_model" "$routed_model" "$last_pin_model" "$command_ids" >"$tmp"
146
152
  chmod 600 "$tmp"
147
153
  mv "$tmp" "$file"
148
154
  }
@@ -153,6 +159,99 @@ cost_file_for() {
153
159
  printf '%s/%s.cost' "$state_root" "$id"
154
160
  }
155
161
 
162
+ context_file_for() {
163
+ local id scope
164
+ id="$(safe_session_id "$1")" || return 1
165
+ scope="$(printf '%s' "$helper_dir" | cksum | awk '{print $1}')"
166
+ printf '%s/%s-%s.context' "$state_root" "$scope" "$id"
167
+ }
168
+
169
+ generation_file_for() {
170
+ local id scope
171
+ id="$(safe_session_id "$1")" || return 1
172
+ scope="$(printf '%s' "$helper_dir" | cksum | awk '{print $1}')"
173
+ printf '%s/active-%s-%s' "$state_root" "$scope" "$id"
174
+ }
175
+
176
+ state_lock_for() {
177
+ local id scope
178
+ id="$(safe_session_id "$1")" || return 1
179
+ scope="$(printf '%s' "$helper_dir" | cksum | awk '{print $1}')"
180
+ printf '%s/state-%s-%s.lock' "$state_root" "$scope" "$id"
181
+ }
182
+
183
+ acquire_state_lock() {
184
+ local lock="$1" attempt=0 lock_mtime now dead
185
+ while ! mkdir "$lock" 2>/dev/null; do
186
+ lock_mtime="$(stat -c %Y "$lock" 2>/dev/null || stat -f %m "$lock" 2>/dev/null)" || lock_mtime=0
187
+ now="$(date +%s 2>/dev/null)" || now=0
188
+ if [ "$lock_mtime" -gt 0 ] && [ $((now - lock_mtime)) -gt 30 ]; then
189
+ dead="${lock}.dead.$$"
190
+ mv "$lock" "$dead" 2>/dev/null || continue
191
+ rmdir "$dead" 2>/dev/null || true
192
+ continue
193
+ fi
194
+ attempt=$((attempt + 1))
195
+ [ "$attempt" -lt 1000 ] || return 1
196
+ sleep 0.01
197
+ done
198
+ return 0
199
+ }
200
+
201
+ release_state_lock() {
202
+ rmdir "$1" 2>/dev/null || true
203
+ }
204
+
205
+ context_snapshot() {
206
+ local file="$1" id="$2" now
207
+ [ -f "$file" ] || return 0
208
+ [ "$(wc -c <"$file")" -le 4096 ] || return 0
209
+ now="$(date +%s)"
210
+ jq -ce --arg session "$id" --argjson now "$now" '
211
+
212
+ def tokens: type == "number" and floor == . and . > 0 and . <= 2147483647;
213
+ def epoch: sub("\\.[0-9]+Z$"; "Z") | fromdateiso8601;
214
+ .context_snapshot as $s |
215
+ select(.session_id == $session and $s.version == 1 and $s.estimate_kind == "approximate") |
216
+ select(($s.estimate_tokens | tokens) and ($s.context_window | tokens) and ($s.output_reserve_tokens | tokens)) |
217
+ select(($s.served_model | type) == "string" and ($s.served_model | test("^[A-Za-z0-9._:/-]{1,128}$"))) |
218
+ select(($s.request_id | type) == "string" and ($s.request_id | length) > 0 and ($s.request_id | length) <= 128) |
219
+ ($s.recorded_at | epoch) as $recorded | ($s.requested_at | epoch) as $requested |
220
+ select($requested > 0 and $requested <= $recorded and $recorded <= $now and $now - $recorded <= 300) |
221
+ $s
222
+ ' "$file" 2>/dev/null || true
223
+ }
224
+
225
+ # The Stop payload preserves this exact router wire record in raw Markdown.
226
+ # A general Markdown parser would add a runtime dependency to standalone installs.
227
+ command_outcome() {
228
+ printf '%s' "$1" | jq -Rsec '
229
+ def safe_identifier: type == "string" and test("^[A-Za-z0-9._:/-]{1,128}$");
230
+ capture("(?:^|\n)\\[weave-router-command-v1\\]: <weave-router:(?<encoded>[A-Za-z0-9_-]{1,8192})>(?:\n|$)").encoded |
231
+ gsub("-"; "+") | gsub("_"; "/") | @base64d | fromjson |
232
+ select(.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}$"))) |
233
+ select(.command == "force_model" or .command == "router_session" or .command == "router_models" or .command == "router_feedback" or .command == "loop_stop") |
234
+ select(.disposition == "accepted" or .disposition == "rejected") |
235
+ select(.pin.transition == "unchanged" or
236
+ (.command == "force_model" and .disposition == "accepted" and
237
+ (.pin.transition == "cleared" or (.pin.transition == "applied" and
238
+ (.pin.model | safe_identifier) and (.pin.provider | safe_identifier) and
239
+ (.pin.effort == null or (.pin.effort | safe_identifier))))))
240
+ ' 2>/dev/null || true
241
+ }
242
+
243
+ pin_clause() {
244
+ [ -z "$last_pin_model" ] || printf ' · last pin: %s' "$(safe_display_value "$last_pin_model")"
245
+ }
246
+
247
+ context_clause() {
248
+ local snapshot="$1"
249
+ [ -n "$snapshot" ] || return 0
250
+ awk -v estimate="$(jq -r '.estimate_tokens' <<<"$snapshot")" -v window="$(jq -r '.context_window' <<<"$snapshot")" 'BEGIN {
251
+ printf " · last Router ctx est. ~%s/%s", (estimate < 1000 ? estimate : sprintf("%.0fk", estimate/1000)), (window < 1000 ? window : sprintf("%.0fk", window/1000))
252
+ }'
253
+ }
254
+
156
255
  # Reads the router base URL and key out of the Codex config this install owns.
157
256
  # Resolved from the helper's own location first so a project-scope install never
158
257
  # reads (or leaks) the user-scope key: the project helper lives in the same
@@ -230,11 +329,11 @@ read_codex_endpoint() {
230
329
  # Fire-and-forget on purpose — a slow or unreachable router must never stall a
231
330
  # Codex turn, and every failure simply leaves the previous cache in place.
232
331
  refresh_session_cost() {
233
- local id="$1" file="$2"
234
- [ "${WEAVE_CODEX_STATUS_SAVINGS:-1}" = "0" ] && return 0
332
+ local id="$1" file="$2" context_file="$3" generation="$4"
333
+ [ "${WEAVE_CODEX_STATUS_SAVINGS:-1}" = "0" ] && [ "${WEAVE_CODEX_STATUS_CONTEXT:-1}" = "0" ] && return 0
235
334
  command -v curl >/dev/null 2>&1 || return 0
236
335
 
237
- local endpoint base_url key
336
+ local endpoint base_url key active_file state_lock
238
337
  endpoint="$(read_codex_endpoint)" || return 0
239
338
  base_url="$(printf '%s' "$endpoint" | sed -n 1p)"
240
339
  key="$(printf '%s' "$endpoint" | sed -n 2p)"
@@ -242,6 +341,8 @@ refresh_session_cost() {
242
341
 
243
342
  mkdir -p "$state_root" 2>/dev/null || return 0
244
343
  chmod 700 "$state_root" 2>/dev/null || true
344
+ active_file="$(generation_file_for "$id")" || return 0
345
+ state_lock="$(state_lock_for "$id")" || return 0
245
346
 
246
347
  (
247
348
  exec </dev/null
@@ -266,29 +367,112 @@ refresh_session_cost() {
266
367
  file://*) ;;
267
368
  *) url="${url%/v1}/v1/sessions/$id/cost" ;;
268
369
  esac
269
- body="$(curl -fsS --max-time 5 -H "X-Weave-Router-Key: $key" "$url" 2>/dev/null)" || exit 0
270
- # savings_usd is the router's own (requested - actual). A body without it
271
- # (404, error envelope, older router) writes nothing and leaves the cache.
272
- savings="$(printf '%s' "$body" | jq -r '.savings_usd // empty' 2>/dev/null)" || exit 0
273
- case "$savings" in
274
- ''|*[!0-9.eE+-]*) exit 0 ;;
275
- esac
276
- tmp="$file.tmp.$$"
277
- mkdir -p "$(dirname "$file")" 2>/dev/null
278
- if printf '%s' "$savings" >"$tmp" 2>/dev/null; then
279
- chmod 600 "$tmp" 2>/dev/null
280
- mv "$tmp" "$file" 2>/dev/null
370
+ header_file="$(mktemp "$state_root/.headers.XXXXXX")" || exit 0
371
+ chmod 600 "$header_file"
372
+ printf 'header = "X-Weave-Router-Key: %s"\n' "$key" >"$header_file"
373
+ if ! body="$(curl -fsS --max-time 5 --max-filesize 8192 -K "$header_file" "$url" 2>/dev/null)"; then
374
+ rm -f "$header_file"
375
+ exit 0
376
+ fi
377
+ rm -f "$header_file"
378
+ [ "$(printf '%s' "$body" | wc -c)" -le 8192 ] || exit 0
379
+ response_session="$(jq -r '.session_id // empty' <<<"$body" 2>/dev/null)" || exit 0
380
+ [ -z "$response_session" ] || [ "$response_session" = "$id" ] || exit 0
381
+ context_tmp=""
382
+ fresh_snapshot=""
383
+ fresh_title=""
384
+ savings_tmp=""
385
+ savings=""
386
+ fresh_model=""
387
+ fresh_requested=""
388
+ if [ "${WEAVE_CODEX_STATUS_CONTEXT:-1}" != "0" ]; then
389
+ context_tmp="$(mktemp "$state_root/.context.XXXXXX")" || exit 0
390
+ chmod 600 "$context_tmp"
391
+ printf '%s' "$body" >"$context_tmp" || { rm -f "$context_tmp"; exit 0; }
392
+ fresh_snapshot="$(context_snapshot "$context_tmp" "$id")"
393
+ if [ -n "$fresh_snapshot" ]; then
394
+ fresh_model="$(safe_display_value "$(jq -r '.served_model' <<<"$fresh_snapshot")")"
395
+ fresh_requested="$(jq -r '.requested_model // empty' <<<"$fresh_snapshot")"
396
+ if { [ -z "$requested_model" ] || [ "$fresh_requested" = "$requested_model" ]; } \
397
+ && { [ -z "$force_model" ] || [ "$fresh_model" = "$(safe_display_value "$force_model")" ]; } \
398
+ && { [ -z "$marker_model" ] || [ "$fresh_model" = "$routed_model" ]; }; then
399
+ shown_requested="$requested_model"
400
+ [ -n "$shown_requested" ] || shown_requested="$(safe_display_value "$fresh_requested")"
401
+ if [ -n "$shown_requested" ] && [ "$fresh_model" != "$shown_requested" ]; then
402
+ fresh_title="Weave Router · $shown_requested → $fresh_model"
403
+ else
404
+ fresh_title="Weave Router · $fresh_model"
405
+ fi
406
+ fi
407
+ fi
408
+ fi
409
+ if [ "${WEAVE_CODEX_STATUS_SAVINGS:-1}" != "0" ]; then
410
+ # savings_usd is the router's own (requested - actual). A body without it
411
+ # (404, error envelope, older router) leaves the cache untouched.
412
+ savings="$(printf '%s' "$body" | jq -r '.savings_usd // empty' 2>/dev/null)" || savings=""
413
+ case "$savings" in ''|*[!0-9.eE+-]*) savings="" ;; esac
414
+ if [ -n "$savings" ]; then
415
+ savings_tmp="$(mktemp "$state_root/.cost.XXXXXX")" || savings=""
416
+ if [ -n "$savings" ]; then
417
+ if ! chmod 600 "$savings_tmp" 2>/dev/null || ! printf '%s' "$savings" >"$savings_tmp" 2>/dev/null; then
418
+ rm -f "$savings_tmp"
419
+ savings_tmp=""
420
+ fi
421
+ fi
422
+ fi
281
423
  fi
282
- rm -f "$tmp" 2>/dev/null
424
+ if ! acquire_state_lock "$state_lock"; then
425
+ rm -f "$context_tmp" "$savings_tmp"
426
+ exit 0
427
+ fi
428
+ trap 'release_state_lock "$state_lock"; rmdir "$lock" 2>/dev/null || true' EXIT
429
+ if [ "$(cat "$active_file" 2>/dev/null)" = "$generation" ]; then
430
+ if [ "${WEAVE_CODEX_STATUS_CONTEXT:-1}" != "0" ]; then
431
+ if [ -n "$fresh_snapshot" ]; then
432
+ existing_snapshot="$(context_snapshot "$context_file" "$id")"
433
+ if [ -n "$existing_snapshot" ] && ! jq -en --argjson incoming "$fresh_snapshot" --argjson existing "$existing_snapshot" '
434
+ def instant:
435
+ capture("^(?<whole>[0-9-]+T[0-9:]+)(?:\\.(?<fraction>[0-9]{1,9}))?Z$") |
436
+ [.whole, ((.fraction // "") + "000000000" | .[:9])];
437
+ [($incoming.requested_at | instant), ($incoming.recorded_at | instant)] as $incoming_time |
438
+ [($existing.requested_at | instant), ($existing.recorded_at | instant)] as $existing_time |
439
+ $incoming_time > $existing_time or
440
+ ($incoming_time == $existing_time and $incoming.request_id == $existing.request_id)
441
+ ' >/dev/null 2>&1; then
442
+ rm -f "$context_tmp" "$savings_tmp"
443
+ exit 0
444
+ elif mv "$context_tmp" "$context_file" 2>/dev/null; then
445
+ context_tmp=""
446
+ else
447
+ fresh_title=""
448
+ fi
449
+ else
450
+ rm -f "$context_file"
451
+ fi
452
+ fi
453
+ if [ -n "$savings_tmp" ]; then
454
+ if mv "$savings_tmp" "$file" 2>/dev/null; then
455
+ savings_tmp=""
456
+ else
457
+ rm -f "$savings_tmp"
458
+ savings_tmp=""
459
+ fi
460
+ fi
461
+ if [ -n "$fresh_title" ] && [ ! -f "$disabled_marker" ]; then
462
+ emit_title "$fresh_title$(savings_clause "$file")$(context_clause "$fresh_snapshot")$(pin_clause)"
463
+ fi
464
+ fi
465
+ release_state_lock "$state_lock"
466
+ rm -f "$context_tmp" "$savings_tmp"
283
467
  ) >/dev/null 2>&1 &
284
468
  disown 2>/dev/null || true
285
469
  }
286
470
 
287
471
  # Renders the cached savings as a display clause, or nothing. Values below a
288
472
  # cent read as "<$0.01" rather than "$0.00", which would be indistinguishable
289
- # from "the router ran and did not beat your selection". Negative totals are
290
- # omitted entirely: the router picked a pricier model for quality on this
291
- # session and "saved -$0.02" is a worse answer than staying quiet.
473
+ # from "the router ran and did not beat your selection". A negative total means
474
+ # the router upgraded hard turns past the requested model; it reads as "cost
475
+ # $X more" rather than a negative saving.
292
476
  savings_clause() {
293
477
  local file="$1" raw
294
478
  [ "${WEAVE_CODEX_STATUS_SAVINGS:-1}" = "0" ] && return 0
@@ -299,6 +483,8 @@ savings_clause() {
299
483
  esac
300
484
  awk -v v="$raw" 'BEGIN{
301
485
  v = v + 0
486
+ if (v <= -0.01) { printf " · cost $%.2f more", -v; exit }
487
+ if (v <= -0.005) { printf " · cost <$0.01 more"; exit }
302
488
  if (v < 0.005) { exit }
303
489
  if (v < 0.01) { printf " · saved <$0.01"; exit }
304
490
  printf " · saved $%.2f", v
@@ -348,6 +534,38 @@ if [ "${WEAVE_CAPTURE_LLM_CLASSIFIER:-}" = "1" ] && [ -n "${WEAVE_CAPTURE_HOOK_T
348
534
  esac
349
535
  fi
350
536
  fi
537
+ session_id="$(safe_session_id "$(jq -r '.session_id // empty' <<<"$payload")")" || exit 0
538
+ active_file="$(generation_file_for "$session_id")"
539
+ state_lock="$(state_lock_for "$session_id")"
540
+ mkdir -p "$state_root"
541
+ chmod 700 "$state_root"
542
+ acquire_state_lock "$state_lock" || exit 0
543
+ trap 'release_state_lock "$state_lock"' EXIT
544
+ turn_file="${active_file}.turn"
545
+ turn_id="$(safe_session_id "$(jq -r '.turn_id // empty' <<<"$payload")")" || turn_id=""
546
+ if [ "$hook_event_name" = "SessionStart" ]; then
547
+ rm -f "$turn_file"
548
+ elif [ "$hook_event_name" = "UserPromptSubmit" ]; then
549
+ if [ -n "$turn_id" ]; then
550
+ printf '%s' "$turn_id" >"$turn_file"
551
+ chmod 600 "$turn_file"
552
+ else
553
+ rm -f "$turn_file"
554
+ fi
555
+ elif [ "$hook_event_name" = "Stop" ] && [ -n "$turn_id" ] && [ -f "$turn_file" ] && [ "$(cat "$turn_file")" != "$turn_id" ]; then
556
+ exit 0
557
+ fi
558
+ generation="$(mktemp "$state_root/.generation.XXXXXX")"
559
+ printf '%s' "$generation" >"$generation"
560
+ chmod 600 "$generation"
561
+ mv "$generation" "$active_file"
562
+ if [ "$hook_event_name" = "SessionStart" ] || [ "$hook_event_name" = "PreCompact" ]; then
563
+ reset_context="$(context_file_for "$session_id")" || reset_context=""
564
+ [ -z "$reset_context" ] || rm -f "$reset_context"
565
+ fi
566
+ if [ "$hook_event_name" = "UserPromptSubmit" ]; then
567
+ exit 0
568
+ fi
351
569
  if [ "$hook_event_name" = "SessionStart" ]; then
352
570
  if [ -f "$disabled_marker" ]; then
353
571
  emit_title "Codex · direct"
@@ -357,7 +575,11 @@ if [ "$hook_event_name" = "SessionStart" ]; then
357
575
  exit 0
358
576
  fi
359
577
 
360
- if [ "$hook_event_name" = "PreToolUse" ] || [ "$hook_event_name" = "PreCompact" ]; then
578
+ if [ "$hook_event_name" = "PreCompact" ]; then
579
+ [ -f "$disabled_marker" ] || emit_title "Weave Router · active"
580
+ exit 0
581
+ fi
582
+ if [ "$hook_event_name" = "PreToolUse" ]; then
361
583
  exit 0
362
584
  fi
363
585
 
@@ -367,6 +589,8 @@ fi
367
589
 
368
590
  requested_model="$(safe_display_value "$(jq -r '.model // ""' <<<"$payload")")"
369
591
  routed_model=""
592
+ last_pin_model=""
593
+ command_ids=""
370
594
  session_id="$(jq -r '.session_id // ""' <<<"$payload")"
371
595
  last_assistant_message="$(jq -r '.last_assistant_message // ""' <<<"$payload")"
372
596
 
@@ -375,31 +599,52 @@ if file="$(state_file_for "$session_id" 2>/dev/null)"; then
375
599
  read_state "$file"
376
600
  fi
377
601
 
378
- # The marker is intentionally matched only at the beginning of the assistant
379
- # message. Do not treat ordinary prose that mentions the heading as metadata.
380
602
  first_line="${last_assistant_message%%$'\n'*}"
381
603
  marker_model=""
382
604
  force_model=""
383
- case "$first_line" in
384
- "${router_badge_sentinel}✦ **Weave Router** → "*)
385
- marker_model="${first_line#"${router_badge_sentinel}✦ **Weave Router** → "}"
386
- marker_model="${marker_model%% ·*}"
387
- ;;
388
- "✦ **Weave Router** → "*)
389
- marker_model="${first_line#"✦ **Weave Router** → "}"
390
- marker_model="${marker_model%% ·*}"
391
- ;;
392
- esac
393
- case "$first_line" in
394
- "Weave Router: force-model applied: "*" ("*)
395
- force_model="${first_line#"Weave Router: force-model applied: "}"
396
- force_model="${force_model%% (*}"
397
- ;;
605
+ structured_command=0
606
+ case "$last_assistant_message" in
607
+ *'[weave-router-command-v'*) structured_command=1 ;;
398
608
  esac
609
+ if [ "$structured_command" = 1 ]; then
610
+ outcome="$(command_outcome "$last_assistant_message")"
611
+ if [ -n "$outcome" ]; then
612
+ outcome_id="$(jq -r '.id' <<<"$outcome")"
613
+ case " $command_ids " in
614
+ *" $outcome_id "*) ;;
615
+ *)
616
+ command_ids="${command_ids:+$command_ids }$outcome_id"
617
+ case "$(jq -r '.pin.transition' <<<"$outcome")" in
618
+ applied)
619
+ last_pin_model="$(jq -r '.pin.model + (if (.pin.effort // "") == "" then "" else ":" + .pin.effort end)' <<<"$outcome")"
620
+ force_model="$(jq -r '.pin.model' <<<"$outcome")"
621
+ ;;
622
+ cleared) last_pin_model="" ;;
623
+ esac
624
+ ;;
625
+ esac
626
+ fi
627
+ else
628
+ # Legacy acknowledgments remain readable; only explicit force and clear mutate history.
629
+ case "$first_line" in
630
+ "Weave Router: force-model applied: "*" ("*|"✦ **Weave Router** → force-model applied: "*" ("*|"Weave Router: force-parent applied: "*" ("*|"✦ **Weave Router** → force-parent applied: "*" ("*)
631
+ force_model="${first_line#*applied: }"
632
+ force_model="${force_model%% (*}"
633
+ last_pin_model="$(safe_display_value "$force_model")"
634
+ ;;
635
+ "Weave Router: force-model cleared"*|"✦ **Weave Router** → force-model cleared"*) last_pin_model="" ;;
636
+ *)
637
+ case "$first_line" in
638
+ "${router_badge_sentinel}✦ **Weave Router** → "*) marker_model="${first_line#"${router_badge_sentinel}✦ **Weave Router** → "}" ;;
639
+ "✦ **Weave Router** → "*) marker_model="${first_line#"✦ **Weave Router** → "}" ;;
640
+ esac
641
+ marker_model="${marker_model%% ·*}"
642
+ case "$marker_model" in ''|*[!A-Za-z0-9._:/-]*) marker_model="" ;; esac
643
+ ;;
644
+ esac
645
+ fi
399
646
  if [ -n "$marker_model" ]; then
400
647
  routed_model="$(safe_display_value "$marker_model")"
401
- elif [ -n "$force_model" ]; then
402
- routed_model="$(safe_display_value "$force_model")"
403
648
  else
404
649
  routed_model="$(safe_display_value "$routed_model")"
405
650
  fi
@@ -413,19 +658,38 @@ fi
413
658
  # turn would not be included even in a blocking read — reading first and
414
659
  # refreshing after costs a turn of freshness and buys never blocking Codex.
415
660
  savings=""
661
+ context=""
662
+ context_file="$(context_file_for "$session_id" 2>/dev/null)" || context_file=""
663
+ if [ -n "$context_file" ] && [ "${WEAVE_CODEX_STATUS_CONTEXT:-1}" != "0" ]; then
664
+ snapshot="$(context_snapshot "$context_file" "$session_id")"
665
+ if [ -n "$snapshot" ]; then
666
+ snapshot_model="$(safe_display_value "$(jq -r '.served_model' <<<"$snapshot")")"
667
+ snapshot_requested="$(jq -r '.requested_model // empty' <<<"$snapshot")"
668
+ if { [ -z "$marker_model" ] || [ "$snapshot_model" = "$routed_model" ]; } && { [ -z "$requested_model" ] || [ "$snapshot_requested" = "$requested_model" ]; } && { [ -z "$force_model" ] || [ "$snapshot_model" = "$(safe_display_value "$force_model")" ]; }; then
669
+ routed_model="$snapshot_model"
670
+ [ -n "$requested_model" ] || requested_model="$(safe_display_value "$snapshot_requested")"
671
+ context="$(context_clause "$snapshot")"
672
+ fi
673
+ fi
674
+ fi
416
675
  cost_file=""
417
676
  if cost_file="$(cost_file_for "$session_id" 2>/dev/null)"; then
418
677
  savings="$(savings_clause "$cost_file")"
419
- refresh_session_cost "$(safe_session_id "$session_id")" "$cost_file"
678
+
420
679
  fi
421
680
 
422
681
  if [ -n "$routed_model" ] && [ -n "$requested_model" ] && [ "$routed_model" != "$requested_model" ]; then
423
- title="Weave Router · $routed_model ← $requested_model$savings"
682
+ title="Weave Router · $requested_model → $routed_model$savings"
424
683
  elif [ -n "$routed_model" ]; then
425
684
  title="Weave Router · $routed_model$savings"
426
685
  elif [ -n "$requested_model" ]; then
427
- title="Weave Router · active ← $requested_model$savings"
686
+ title="Weave Router · $requested_model → active$savings"
428
687
  else
429
688
  title="Weave Router · active$savings"
430
689
  fi
431
- emit_title "$title"
690
+ emit_title "$title$context$(pin_clause)"
691
+ release_state_lock "$state_lock"
692
+ trap - EXIT
693
+ if [ -n "$cost_file" ] && [ -n "$context_file" ]; then
694
+ refresh_session_cost "$(safe_session_id "$session_id")" "$cost_file" "$context_file" "$generation"
695
+ fi
package/codex-toggle.sh CHANGED
@@ -173,7 +173,7 @@ trap "rm -f '$out_file'" EXIT
173
173
  # word-split at runtime -- the braces are a template token, not an expansion.
174
174
  # shellcheck disable=SC1083
175
175
  run_bounded "$WEAVE_TOGGLE_TIMEOUT" "$out_file" \
176
- npx --package @weave-os/router -y -- weave-router "$toggle" --codex{{SCOPE}}
176
+ env NPM_CONFIG_UPDATE_NOTIFIER=false npx --package @weave-os/router -y -- weave-router "$toggle" --codex{{SCOPE}}
177
177
  status=$?
178
178
 
179
179
  output="$(cat "$out_file" 2>/dev/null || true)"
@@ -0,0 +1,6 @@
1
+ ---
2
+ description: Pin only this parent thread to a model while subagents route automatically.
3
+ argument-hint: <model-id>[:effort]
4
+ ---
5
+
6
+ /force-parent $ARGUMENTS
@@ -38,7 +38,7 @@ Other things I might ask for:
38
38
 
39
39
  If the command reports that this router doesn't expose model selection, that's
40
40
  a Weave-hosted router: model selection belongs to the whole organization there,
41
- so tell me to change it at https://router.workweave.ai/dashboard/settings —
41
+ so tell me to change it at https://router.weaveos.com/models —
42
42
  don't try to work around it. Its listing carries no on/off state, so present it
43
43
  as a plain list; don't infer which models are enabled.
44
44
 
@@ -38,7 +38,7 @@ Other things I might ask for:
38
38
 
39
39
  If the command reports that this router doesn't expose model selection, that's
40
40
  a Weave-hosted router: model selection belongs to the whole organization there,
41
- so tell me to change it at https://router.workweave.ai/dashboard/settings —
41
+ so tell me to change it at https://router.weaveos.com/models —
42
42
  don't try to work around it. Its listing carries no on/off state, so present it
43
43
  as a plain list; don't infer which models are enabled.
44
44
 
package/directives.tsv CHANGED
@@ -2,6 +2,7 @@
2
2
  # canonical|aliases|capability|claude|codex|opencode|pi|cursor|adapter
3
3
  # aliases are comma-separated; client columns are yes/no. adapter is the native asset kind.
4
4
  force-model|fm|prompt|yes|yes|yes|yes|manual|command,skill
5
+ force-parent||prompt|yes|yes|yes|yes|manual|command,skill
5
6
  unforce-model|ufm|prompt|yes|yes|yes|yes|manual|command,skill
6
7
  router-feedback|rf|prompt|yes|yes|yes|no|manual|command,skill
7
8
  router-off||local-toggle|yes|yes|no|no|manual|command,skill