@weave-os/router 0.2.28 → 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.
@@ -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.
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ if [ "$#" -ne 1 ] || [ -z "${1:-}" ]; then
4
+ echo "usage: emit.sh <model-id>[:effort]" >&2
5
+ exit 1
6
+ fi
7
+ printf ' /force-parent %s\n' "$1"
@@ -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/dashboard/settings —
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
 
package/codex-status.sh CHANGED
@@ -18,6 +18,7 @@
18
18
  # blocks on the network, and every failure path leaves the title model-only.
19
19
 
20
20
  set -euo pipefail
21
+ export PATH="$PATH:$HOME/.weave/bin"
21
22
 
22
23
  # ---------- background self-refresh ----------
23
24
  #
@@ -92,6 +93,9 @@ weave_self_refresh() {
92
93
  return 0
93
94
  }
94
95
 
96
+ async_title_enabled=0
97
+ [ ! -t 2 ] || async_title_enabled=1
98
+
95
99
  state_root="${XDG_CACHE_HOME:-$HOME/.cache}/weave-router/codex"
96
100
  helper_dir="$(cd "$(dirname "$0")" 2>/dev/null && pwd -P)"
97
101
  disabled_marker="$helper_dir/.weave-router-disabled"
@@ -101,7 +105,7 @@ emit_title() {
101
105
  local title="$1"
102
106
  if [ -n "${WEAVE_CODEX_STATUS_TITLE_FILE:-}" ]; then
103
107
  printf '%s\n' "$title" >"$WEAVE_CODEX_STATUS_TITLE_FILE"
104
- elif [ -t 2 ] && [ -w /dev/tty ]; then
108
+ elif { [ -t 2 ] || [ "${async_title_enabled:-0}" = "1" ]; } && [ -w /dev/tty ]; then
105
109
  printf '\033]0;%s\007' "$title" >/dev/tty
106
110
  fi
107
111
  return 0
@@ -117,13 +121,14 @@ safe_session_id() {
117
121
  }
118
122
 
119
123
  safe_display_value() {
120
- 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
121
125
  }
122
126
 
123
127
  state_file_for() {
124
- local id
128
+ local id scope
125
129
  id="$(safe_session_id "$1")" || return 1
126
- 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"
127
132
  }
128
133
 
129
134
  read_state() {
@@ -132,6 +137,8 @@ read_state() {
132
137
  while IFS='=' read -r key value; do
133
138
  case "$key" in
134
139
  routed_model) routed_model="$value" ;;
140
+ last_pin_model) last_pin_model="$value" ;;
141
+ command_ids) command_ids="$value" ;;
135
142
  esac
136
143
  done <"$file"
137
144
  }
@@ -141,7 +148,7 @@ write_state() {
141
148
  mkdir -p "$state_root"
142
149
  chmod 700 "$state_root"
143
150
  tmp="$(mktemp "$state_root/.state.XXXXXX")"
144
- 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"
145
152
  chmod 600 "$tmp"
146
153
  mv "$tmp" "$file"
147
154
  }
@@ -152,6 +159,99 @@ cost_file_for() {
152
159
  printf '%s/%s.cost' "$state_root" "$id"
153
160
  }
154
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
+
155
255
  # Reads the router base URL and key out of the Codex config this install owns.
156
256
  # Resolved from the helper's own location first so a project-scope install never
157
257
  # reads (or leaks) the user-scope key: the project helper lives in the same
@@ -229,11 +329,11 @@ read_codex_endpoint() {
229
329
  # Fire-and-forget on purpose — a slow or unreachable router must never stall a
230
330
  # Codex turn, and every failure simply leaves the previous cache in place.
231
331
  refresh_session_cost() {
232
- local id="$1" file="$2"
233
- [ "${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
234
334
  command -v curl >/dev/null 2>&1 || return 0
235
335
 
236
- local endpoint base_url key
336
+ local endpoint base_url key active_file state_lock
237
337
  endpoint="$(read_codex_endpoint)" || return 0
238
338
  base_url="$(printf '%s' "$endpoint" | sed -n 1p)"
239
339
  key="$(printf '%s' "$endpoint" | sed -n 2p)"
@@ -241,6 +341,8 @@ refresh_session_cost() {
241
341
 
242
342
  mkdir -p "$state_root" 2>/dev/null || return 0
243
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
244
346
 
245
347
  (
246
348
  exec </dev/null
@@ -265,29 +367,112 @@ refresh_session_cost() {
265
367
  file://*) ;;
266
368
  *) url="${url%/v1}/v1/sessions/$id/cost" ;;
267
369
  esac
268
- body="$(curl -fsS --max-time 5 -H "X-Weave-Router-Key: $key" "$url" 2>/dev/null)" || exit 0
269
- # savings_usd is the router's own (requested - actual). A body without it
270
- # (404, error envelope, older router) writes nothing and leaves the cache.
271
- savings="$(printf '%s' "$body" | jq -r '.savings_usd // empty' 2>/dev/null)" || exit 0
272
- case "$savings" in
273
- ''|*[!0-9.eE+-]*) exit 0 ;;
274
- esac
275
- tmp="$file.tmp.$$"
276
- mkdir -p "$(dirname "$file")" 2>/dev/null
277
- if printf '%s' "$savings" >"$tmp" 2>/dev/null; then
278
- chmod 600 "$tmp" 2>/dev/null
279
- 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
280
423
  fi
281
- 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"
282
467
  ) >/dev/null 2>&1 &
283
468
  disown 2>/dev/null || true
284
469
  }
285
470
 
286
471
  # Renders the cached savings as a display clause, or nothing. Values below a
287
472
  # cent read as "<$0.01" rather than "$0.00", which would be indistinguishable
288
- # from "the router ran and did not beat your selection". Negative totals are
289
- # omitted entirely: the router picked a pricier model for quality on this
290
- # 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.
291
476
  savings_clause() {
292
477
  local file="$1" raw
293
478
  [ "${WEAVE_CODEX_STATUS_SAVINGS:-1}" = "0" ] && return 0
@@ -298,6 +483,8 @@ savings_clause() {
298
483
  esac
299
484
  awk -v v="$raw" 'BEGIN{
300
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 }
301
488
  if (v < 0.005) { exit }
302
489
  if (v < 0.01) { printf " · saved <$0.01"; exit }
303
490
  printf " · saved $%.2f", v
@@ -347,6 +534,38 @@ if [ "${WEAVE_CAPTURE_LLM_CLASSIFIER:-}" = "1" ] && [ -n "${WEAVE_CAPTURE_HOOK_T
347
534
  esac
348
535
  fi
349
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
350
569
  if [ "$hook_event_name" = "SessionStart" ]; then
351
570
  if [ -f "$disabled_marker" ]; then
352
571
  emit_title "Codex · direct"
@@ -356,7 +575,11 @@ if [ "$hook_event_name" = "SessionStart" ]; then
356
575
  exit 0
357
576
  fi
358
577
 
359
- 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
360
583
  exit 0
361
584
  fi
362
585
 
@@ -366,6 +589,8 @@ fi
366
589
 
367
590
  requested_model="$(safe_display_value "$(jq -r '.model // ""' <<<"$payload")")"
368
591
  routed_model=""
592
+ last_pin_model=""
593
+ command_ids=""
369
594
  session_id="$(jq -r '.session_id // ""' <<<"$payload")"
370
595
  last_assistant_message="$(jq -r '.last_assistant_message // ""' <<<"$payload")"
371
596
 
@@ -374,31 +599,52 @@ if file="$(state_file_for "$session_id" 2>/dev/null)"; then
374
599
  read_state "$file"
375
600
  fi
376
601
 
377
- # The marker is intentionally matched only at the beginning of the assistant
378
- # message. Do not treat ordinary prose that mentions the heading as metadata.
379
602
  first_line="${last_assistant_message%%$'\n'*}"
380
603
  marker_model=""
381
604
  force_model=""
382
- case "$first_line" in
383
- "${router_badge_sentinel}✦ **Weave Router** → "*)
384
- marker_model="${first_line#"${router_badge_sentinel}✦ **Weave Router** → "}"
385
- marker_model="${marker_model%% ·*}"
386
- ;;
387
- "✦ **Weave Router** → "*)
388
- marker_model="${first_line#"✦ **Weave Router** → "}"
389
- marker_model="${marker_model%% ·*}"
390
- ;;
391
- esac
392
- case "$first_line" in
393
- "Weave Router: force-model applied: "*" ("*)
394
- force_model="${first_line#"Weave Router: force-model applied: "}"
395
- force_model="${force_model%% (*}"
396
- ;;
605
+ structured_command=0
606
+ case "$last_assistant_message" in
607
+ *'[weave-router-command-v'*) structured_command=1 ;;
397
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
398
646
  if [ -n "$marker_model" ]; then
399
647
  routed_model="$(safe_display_value "$marker_model")"
400
- elif [ -n "$force_model" ]; then
401
- routed_model="$(safe_display_value "$force_model")"
402
648
  else
403
649
  routed_model="$(safe_display_value "$routed_model")"
404
650
  fi
@@ -412,19 +658,38 @@ fi
412
658
  # turn would not be included even in a blocking read — reading first and
413
659
  # refreshing after costs a turn of freshness and buys never blocking Codex.
414
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
415
675
  cost_file=""
416
676
  if cost_file="$(cost_file_for "$session_id" 2>/dev/null)"; then
417
677
  savings="$(savings_clause "$cost_file")"
418
- refresh_session_cost "$(safe_session_id "$session_id")" "$cost_file"
678
+
419
679
  fi
420
680
 
421
681
  if [ -n "$routed_model" ] && [ -n "$requested_model" ] && [ "$routed_model" != "$requested_model" ]; then
422
- title="Weave Router · $routed_model ← $requested_model$savings"
682
+ title="Weave Router · $requested_model → $routed_model$savings"
423
683
  elif [ -n "$routed_model" ]; then
424
684
  title="Weave Router · $routed_model$savings"
425
685
  elif [ -n "$requested_model" ]; then
426
- title="Weave Router · active ← $requested_model$savings"
686
+ title="Weave Router · $requested_model → active$savings"
427
687
  else
428
688
  title="Weave Router · active$savings"
429
689
  fi
430
- 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
@@ -29,6 +29,7 @@
29
29
  # fire.
30
30
 
31
31
  set -uo pipefail
32
+ export PATH="$PATH:$HOME/.weave/bin"
32
33
 
33
34
  # How long the toggle may take before the hook gives up and passes the prompt
34
35
  # through. npx resolves from cache after first use; the budget covers a cold
@@ -172,7 +173,7 @@ trap "rm -f '$out_file'" EXIT
172
173
  # word-split at runtime -- the braces are a template token, not an expansion.
173
174
  # shellcheck disable=SC1083
174
175
  run_bounded "$WEAVE_TOGGLE_TIMEOUT" "$out_file" \
175
- 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}}
176
177
  status=$?
177
178
 
178
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.workweave.ai/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.workweave.ai/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