@weave-os/router 0.2.16 → 0.2.18

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,26 @@
1
+ ---
2
+ name: router-session
3
+ description: "Print the session id that correlates this Codex session in Weave Router telemetry and logs."
4
+ ---
5
+
6
+ <!-- weave-router managed router-session skill -->
7
+
8
+ When the user invokes `$router-session`, run this skill's `scripts/emit.sh` using the
9
+ absolute path shown in this skill's `<path>` (its directory + `/scripts/emit.sh`).
10
+ It takes no arguments.
11
+
12
+ The script prints the session id on its own line. Report that id back in one line,
13
+ formatted as inline code so the user can copy it. Do not send a user message and do
14
+ not type a Codex slash command.
15
+
16
+ The router carries this id as `Session-Id` on every request and stores it for
17
+ analytics joins, so it is also the lookup key in the router dashboard.
18
+
19
+ This skill needs `CODEX_SESSION_ID` in the environment. If it is unset the script
20
+ exits non-zero rather than reporting an id: the alternative is reading the newest
21
+ rollout transcript, which names a different session whenever two run at once, and
22
+ a wrong id sends someone else's session to support. Report the error as-is instead
23
+ of guessing.
24
+
25
+ Codex also prints the same id in its own session banner, which is the quickest
26
+ answer when this skill cannot produce one.
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env bash
2
+ # Print this Codex session's id. Local only -- no router call, no model turn.
3
+ set -uo pipefail
4
+
5
+ if [ -n "${CODEX_SESSION_ID:-}" ]; then
6
+ printf '%s\n' "$CODEX_SESSION_ID"
7
+ exit 0
8
+ fi
9
+
10
+ # No CODEX_SESSION_ID means there is no way to identify *this* session from here.
11
+ # Reading the newest rollout transcript would name whichever session wrote last,
12
+ # which is a different session whenever two run concurrently -- and a wrong id
13
+ # silently attributes feedback to someone else's session. Fail instead.
14
+ echo "session id unavailable: CODEX_SESSION_ID is not set in this environment." >&2
15
+ echo "Codex prints the same id in its session banner." >&2
16
+ exit 1
package/codex-status.sh CHANGED
@@ -93,11 +93,6 @@ state_root="${XDG_CACHE_HOME:-$HOME/.cache}/weave-router/codex"
93
93
  helper_dir="$(cd "$(dirname "$0")" 2>/dev/null && pwd -P)"
94
94
  disabled_marker="$helper_dir/.weave-router-disabled"
95
95
  router_badge_sentinel=$'⁣⁠⁣⁠'
96
- # Must stay verbatim in sync with install.sh / uninstall.sh: the endpoint read
97
- # below is scoped to this block so a key-shaped string elsewhere in the user's
98
- # config.toml is never adopted.
99
- codex_begin_marker="# >>> weave-router managed (do not edit between markers) >>>"
100
- codex_end_marker="# <<< weave-router managed <<<"
101
96
 
102
97
  emit_title() {
103
98
  local title="$1"
@@ -157,10 +152,18 @@ cost_file_for() {
157
152
  # Resolved from the helper's own location first so a project-scope install never
158
153
  # reads (or leaks) the user-scope key: the project helper lives in the same
159
154
  # .codex directory as its config, while the user-scope helper sits in ~/.weave
160
- # and reads ~/.codex. Values are scoped to the managed block so a key-shaped
161
- # string the user wrote elsewhere in the file is never adopted. awk, not a TOML
162
- # parser, because the Codex target deliberately does not require jq for config
163
- # reads.
155
+ # and reads ~/.codex. Values are scoped to the [model_providers.weave] table so
156
+ # a key-shaped string the user wrote elsewhere in the file is never adopted. awk,
157
+ # not a TOML parser, because the Codex target deliberately does not require jq
158
+ # for config reads.
159
+ #
160
+ # Scoped to the table rather than the managed comment markers, and matching the
161
+ # header name quoted or bare, because Codex rewrites config.toml through a TOML
162
+ # serializer whenever it persists its own state: comments do not survive, so the
163
+ # markers vanish while the table remains, and the inline http_headers come back
164
+ # as a subtable with the header name unquoted. A marker-scoped, quoted-only read
165
+ # resolved nothing on any config Codex had touched, which silently dropped the
166
+ # savings figure from the title with no error anywhere.
164
167
  read_codex_endpoint() {
165
168
  local config=""
166
169
  # Project/custom installs name the helper weave-status.sh and keep it next
@@ -173,19 +176,45 @@ read_codex_endpoint() {
173
176
  config="$HOME/.codex/config.toml"
174
177
  fi
175
178
  [ -n "$config" ] || return 0
176
- awk -v begin="$codex_begin_marker" -v end="$codex_end_marker" '
177
- $0 == begin { inblk = 1; next }
178
- $0 == end { inblk = 0; next }
179
- !inblk { next }
179
+ awk '
180
+ # Cut a TOML comment, honouring quoted strings so a # inside a value stays.
181
+ # A full-line comment reduces to empty and matches nothing below, so this
182
+ # replaces a separate skip rule -- and unlike one, it also catches a comment
183
+ # trailing another assignment, which the unanchored matches would otherwise
184
+ # read as live config on any line preceding the real value.
185
+ function weave_strip_comment(line, i, c, out, indq, insq, esc) {
186
+ out = ""
187
+ indq = 0
188
+ insq = 0
189
+ esc = 0
190
+ for (i = 1; i <= length(line); i++) {
191
+ c = substr(line, i, 1)
192
+ if (esc) { out = out c; esc = 0; continue }
193
+ # Only basic strings have escapes; a backslash in a literal string is
194
+ # data, so consuming the next character there would mis-track the quote.
195
+ if (indq && c == "\\") { out = out c; esc = 1; continue }
196
+ if (!insq && c == "\"") { indq = !indq; out = out c; continue }
197
+ if (!indq && c == "'"'"'") { insq = !insq; out = out c; continue }
198
+ if (c == "#" && !indq && !insq) break
199
+ out = out c
200
+ }
201
+ return out
202
+ }
203
+ { $0 = weave_strip_comment($0) }
204
+ /^[[:space:]]*\[/ {
205
+ in_provider = ($0 ~ /^[[:space:]]*\[[[:space:]]*model_providers[[:space:]]*\.[[:space:]]*weave[[:space:]]*(\.[^]]*)?\][[:space:]]*(#.*)?$/)
206
+ next
207
+ }
208
+ !in_provider { next }
180
209
  match($0, /base_url[[:space:]]*=[[:space:]]*"[^"]*"/) {
181
210
  v = substr($0, RSTART, RLENGTH)
182
211
  sub(/^.*=[[:space:]]*"/, "", v); sub(/"$/, "", v)
183
- url = v
212
+ if (url == "") url = v
184
213
  }
185
- match($0, /"X-Weave-Router-Key"[[:space:]]*=[[:space:]]*"[^"]*"/) {
214
+ match($0, /"?X-Weave-Router-Key"?[[:space:]]*=[[:space:]]*"[^"]*"/) {
186
215
  v = substr($0, RSTART, RLENGTH)
187
216
  sub(/^.*=[[:space:]]*"/, "", v); sub(/"$/, "", v)
188
- key = v
217
+ if (key == "") key = v
189
218
  }
190
219
  END { if (url != "" && key != "") printf "%s\n%s\n", url, key }
191
220
  ' "$config" 2>/dev/null || true
package/directives.tsv CHANGED
@@ -7,7 +7,7 @@ router-feedback|rf|prompt|yes|yes|yes|no|manual|command,skill
7
7
  router-off||local-toggle|yes|yes|no|no|manual|command,skill
8
8
  router-on||local-toggle|yes|yes|no|no|manual|command,skill
9
9
  router-status||local-toggle|yes|yes|no|no|manual|command,skill
10
- router-session||prompt|yes|no|no|no|manual|command
10
+ router-session||prompt|yes|yes|no|no|manual|command,skill
11
11
  router-models|models|local-toggle|yes|yes|no|no|manual|command,skill
12
12
  disable-routing||local-toggle|no|yes|no|no|manual|skill
13
13
  beta||prompt|yes|no|no|yes|manual|command
package/install.sh CHANGED
@@ -483,6 +483,147 @@ resolve_user_email() {
483
483
  esac
484
484
  }
485
485
 
486
+ # strip_weave_codex_hooks rewrites config.toml without any hook registration
487
+ # this installer owns, matched by the helper filename rather than by position.
488
+ #
489
+ # Two reasons it cannot key on the managed markers. Codex rewrites config.toml
490
+ # through a TOML serializer when it persists its own state, so our registrations
491
+ # routinely end up outside them — a later install then appends a fresh copy and
492
+ # the helper runs twice per event. And the retired directive hook has to be
493
+ # removed from configs that already carry it, wherever it now sits.
494
+ #
495
+ # Removal is per sub-entry, not per group: a [[hooks.Stop]] group can hold our
496
+ # hook and a third party's, and dropping the group would take theirs with it.
497
+ # The group header goes only once nothing is left inside it.
498
+ # Ownership contract for the Codex hook helpers. Every rule here was a bug
499
+ # first; keep them together so the next change has the whole set.
500
+ #
501
+ # 1. Ours is decided per path by that helper's EXACT marker. A prefix match
502
+ # lets the status marker vouch for the directive path, and the two
503
+ # deletion sites check exact markers -- so the strip would unwire a file
504
+ # it then declines to delete.
505
+ # 2. A missing file is ours. Its registration points at nothing, which is
506
+ # residue we left behind.
507
+ # 3. What a symlink means depends on the helper's lifecycle, so the caller
508
+ # says which it is.
509
+ # rewrite (status): the file is rewritten in place and never deleted, so
510
+ # the link is followed to read the marker. Disowning it instead leaves
511
+ # the old registrations while the managed block adds a fresh pair,
512
+ # stacking the duplicates this strip exists to remove.
513
+ # delete (directive): the file is removed, and removal refuses to act
514
+ # through a link. Claiming one would strip the registration and then
515
+ # decline the delete, leaving a helper Codex no longer runs -- rule 4
516
+ # violated in the one case it exists for.
517
+ # Either way the check precedes -e, which is false for a dangling link: it
518
+ # then fails the marker test and stays the user's, rather than being
519
+ # claimed by rule 2.
520
+ # 4. Registration and file must be decided together. Removing one while
521
+ # keeping the other leaves a script Codex never runs, with nothing on
522
+ # screen to explain it.
523
+ # 5. Compare decoded paths. The command value is a TOML basic string and the
524
+ # writer escapes it, so a raw comparison misses any path with a quote or
525
+ # backslash.
526
+ # warn_if_symlink reports a symlinked path and returns non-zero so the caller
527
+ # can skip just that file. refuse_if_symlink exits the process, which is right
528
+ # for a path we are about to write but wrong for these helpers: one symlinked
529
+ # helper would abort the whole run, stranding the config rewrite that is the
530
+ # actual work. Neither is deleted through a link either way.
531
+ warn_if_symlink() {
532
+ local target="$1"
533
+ [ -L "$target" ] || return 0
534
+ warn "$target is a symlink (-> $(readlink "$target")); leaving it untouched."
535
+ return 1
536
+ }
537
+
538
+ weave_owns_codex_helper() {
539
+ local path="$1" marker="$2" lifecycle="$3"
540
+ [ -n "$path" ] && [ -n "$marker" ] && [ -n "$lifecycle" ] || return 1
541
+ if [ -L "$path" ]; then
542
+ [ "$lifecycle" = "rewrite" ] || return 1
543
+ grep -Fq "$marker" "$path" 2>/dev/null
544
+ return $?
545
+ fi
546
+ [ -e "$path" ] || return 0
547
+ grep -Fq "$marker" "$path" 2>/dev/null
548
+ }
549
+
550
+ # weave_owned_codex_helpers prints, one per line, whichever of the two helper
551
+ # paths this installation may unwire.
552
+ weave_owned_codex_helpers() {
553
+ weave_owns_codex_helper "${codex_status_file:-}" '<!-- weave-router managed codex status -->' rewrite \
554
+ && printf '%s\n' "$codex_status_file"
555
+ weave_owns_codex_helper "${codex_directive_file:-}" '<!-- weave-router managed codex directive -->' delete \
556
+ && printf '%s\n' "$codex_directive_file"
557
+ return 0
558
+ }
559
+
560
+ strip_weave_codex_hooks() {
561
+ local config_file="$1"; shift
562
+ [ -f "$config_file" ] || return 0
563
+ # Exact paths, never a filename pattern: a third party's hook is free to be
564
+ # called weave-status.sh, and matching on the basename would delete it.
565
+ local owned="" candidate
566
+ for candidate in "$@"; do
567
+ [ -n "$candidate" ] || continue
568
+ # A unit separator, not a newline: BSD awk rejects an embedded newline in a
569
+ # -v value outright ("newline in string"), which silently disabled the whole
570
+ # pass on macOS.
571
+ owned="${owned}${candidate}$(printf '\037')"
572
+ done
573
+ [ -n "$owned" ] || return 0
574
+ local tmp; tmp="$(mktemp -t weave-codex-hooks.XXXXXX)"
575
+ awk -v owned="$owned" '
576
+ BEGIN {
577
+ n = split(owned, list, "\037")
578
+ for (i = 1; i <= n; i++) if (list[i] != "") own[list[i]] = 1
579
+ }
580
+ function flush_sub( i) {
581
+ if (sub_n == 0) return
582
+ if (!sub_is_weave) {
583
+ if (group_pending != "") {
584
+ print group_pending
585
+ group_pending = ""
586
+ if (group_blank) { print ""; group_blank = 0 }
587
+ }
588
+ for (i = 1; i <= sub_n; i++) print sub_line[i]
589
+ }
590
+ sub_n = 0
591
+ sub_is_weave = 0
592
+ }
593
+ function close_group() { flush_sub(); group_pending = ""; group_blank = 0 }
594
+ /^[[:space:]]*\[\[hooks\.[A-Za-z]+\.hooks\]\][[:space:]]*$/ {
595
+ flush_sub(); sub_n = 1; sub_line[1] = $0; next
596
+ }
597
+ /^[[:space:]]*\[\[hooks\.[A-Za-z]+\]\][[:space:]]*$/ {
598
+ close_group(); group_pending = $0; next
599
+ }
600
+ /^[[:space:]]*\[/ { close_group(); print; next }
601
+ {
602
+ if (sub_n > 0) {
603
+ sub_line[++sub_n] = $0
604
+ if (match($0, /^[[:space:]]*command[[:space:]]*=[[:space:]]*"([^"\\]|\\.)*"/)) {
605
+ v = substr($0, RSTART, RLENGTH)
606
+ sub(/^[^"]*"/, "", v); sub(/"$/, "", v)
607
+ # write_codex_config escapes the path before writing it, so undo that
608
+ # before comparing; quotes first, then backslashes.
609
+ gsub(/\\"/, "\"", v)
610
+ gsub(/\\\\/, "\\", v)
611
+ if (v in own) sub_is_weave = 1
612
+ }
613
+ next
614
+ }
615
+ if (group_pending != "" && $0 ~ /^[[:space:]]*$/) { group_blank = 1; next }
616
+ if (group_pending != "") {
617
+ print group_pending; group_pending = ""
618
+ if (group_blank) { print ""; group_blank = 0 }
619
+ }
620
+ print
621
+ }
622
+ END { close_group() }
623
+ ' "$config_file" >"$tmp" && mv "$tmp" "$config_file"
624
+ rm -f "$tmp" 2>/dev/null || true
625
+ }
626
+
486
627
  # write_codex_config writes a managed [model_providers.weave] block to the
487
628
  # Codex CLI's config.toml. Sets `model_provider = "weave"` at the top level so
488
629
  # Codex picks the routed provider by default. The provider requires OpenAI
@@ -596,15 +737,34 @@ TOML
596
737
 
597
738
  if [ -f "$config_file" ]; then
598
739
  local tmp; tmp="$(mktemp -t weave-codex.XXXXXX)"
599
- # Strip the managed block (between markers) plus any top-level
600
- # `model_provider =` outside it. We define "top-level" as everything
601
- # before the first `[section]` header. The awk handles both passes in
602
- # one sweep so we never emit a duplicate.
740
+ # Strip the managed block (between markers), any top-level
741
+ # `model_provider =` outside it, and any `[model_providers.weave]` table
742
+ # (with its subtables) outside it. "Top-level" means everything before the
743
+ # first `[section]` header. The awk handles every pass in one sweep so we
744
+ # never emit a duplicate.
745
+ #
746
+ # Dropping the out-of-marker provider table is what keeps a re-install
747
+ # idempotent once Codex has rewritten config.toml itself. Codex round-trips
748
+ # the whole file through a TOML serializer when it persists its own state
749
+ # (hook trust hashes, project trust levels), and comments do not survive
750
+ # that: the markers vanish while `[model_providers.weave]` remains. Keying
751
+ # the strip on the markers alone then left the stale table in place and
752
+ # appended a second one -- TOML rejects a table declared twice, so Codex
753
+ # refused to start with "duplicate key" while the installer reported
754
+ # success.
603
755
  awk -v begin="$WEAVE_CODEX_BEGIN_MARKER" -v end="$WEAVE_CODEX_END_MARKER" '
604
756
  $0 == begin { skip = 1; next }
605
757
  $0 == end { skip = 0; next }
606
758
  skip { next }
607
- /^[[:space:]]*\[/ { in_section = 1 }
759
+ /^[[:space:]]*\[/ {
760
+ in_section = 1
761
+ if ($0 ~ /^[[:space:]]*\[[[:space:]]*model_providers[[:space:]]*\.[[:space:]]*weave[[:space:]]*(\.[^]]*)?\][[:space:]]*(#.*)?$/) {
762
+ in_weave_provider = 1
763
+ next
764
+ }
765
+ in_weave_provider = 0
766
+ }
767
+ in_weave_provider { next }
608
768
  !in_section && /^[[:space:]]*model_provider[[:space:]]*=/ { next }
609
769
  { print }
610
770
  ' "$config_file" >"$tmp"
@@ -620,6 +780,16 @@ TOML
620
780
  # <our managed block> ← model_provider stays top-level
621
781
  # [model_providers.weave] ← scoped section, OK anywhere
622
782
  # <user's sections> ← re-scope, unaffected
783
+ # Drop every registration we own first; the managed block below re-adds
784
+ # exactly the ones this version still ships. The section scan has to run
785
+ # after it, since removing a group can move the first header.
786
+ local owned_helpers=()
787
+ while IFS= read -r owned_helper; do
788
+ [ -n "$owned_helper" ] && owned_helpers+=("$owned_helper")
789
+ done <<EOF
790
+ $(weave_owned_codex_helpers)
791
+ EOF
792
+ strip_weave_codex_hooks "$tmp" ${owned_helpers[@]+"${owned_helpers[@]}"}
623
793
  local first_section
624
794
  first_section="$(awk '/^[[:space:]]*\[/ { print NR; exit }' "$tmp")"
625
795
  if [ -n "$first_section" ]; then
@@ -1509,7 +1679,7 @@ router-feedback|rf|prompt|yes|yes|yes|no|manual|command,skill
1509
1679
  router-off||local-toggle|yes|yes|no|no|manual|command,skill
1510
1680
  router-on||local-toggle|yes|yes|no|no|manual|command,skill
1511
1681
  router-status||local-toggle|yes|yes|no|no|manual|command,skill
1512
- router-session||prompt|yes|no|no|no|manual|command
1682
+ router-session||prompt|yes|yes|no|no|manual|command,skill
1513
1683
  router-models|models|local-toggle|yes|yes|no|no|manual|command,skill
1514
1684
  disable-routing||local-toggle|no|yes|no|no|manual|skill
1515
1685
  beta||prompt|yes|no|no|yes|manual|command
@@ -1682,8 +1852,10 @@ elif [ "$target" = "codex" ]; then
1682
1852
  codex_config_file="$codex_dir/config.toml"
1683
1853
  if [ "$scope" = "user" ] && [ -z "$install_dir" ]; then
1684
1854
  codex_status_file="$settings_base/.weave/codex-status.sh"
1855
+ codex_directive_file="$settings_base/.weave/codex-directive.sh"
1685
1856
  else
1686
1857
  codex_status_file="$codex_dir/weave-status.sh"
1858
+ codex_directive_file="$codex_dir/weave-directive.sh"
1687
1859
  fi
1688
1860
  codex_status_disabled_marker="$(dirname "$codex_status_file")/.weave-router-disabled"
1689
1861
 
@@ -1848,10 +2020,19 @@ key_source_is_own() {
1848
2020
  read_codex_key() {
1849
2021
  local f="$1"
1850
2022
  key_source_is_own "$f" || return 0
1851
- awk -v begin="$WEAVE_CODEX_BEGIN_MARKER" -v end="$WEAVE_CODEX_END_MARKER" '
1852
- $0 == begin { inblk = 1; next }
1853
- $0 == end { inblk = 0; next }
1854
- inblk && match($0, /"X-Weave-Router-Key"[[:space:]]*=[[:space:]]*"[^"]*"/) {
2023
+ # Scan the [model_providers.weave] table and its subtables rather than the
2024
+ # managed markers, and accept the header name quoted or bare. Our own writer
2025
+ # emits one inline `http_headers = { "X-Weave-Router-Key" = "..." }`; Codex's
2026
+ # serializer re-emits the same value as a bare key in a
2027
+ # [model_providers.weave.http_headers] subtable. Matching only the quoted
2028
+ # in-marker spelling missed the key on any config Codex had rewritten, and a
2029
+ # re-install then minted a second router key instead of reusing this one.
2030
+ awk '
2031
+ /^[[:space:]]*\[/ {
2032
+ in_provider = ($0 ~ /^[[:space:]]*\[[[:space:]]*model_providers[[:space:]]*\.[[:space:]]*weave[[:space:]]*(\.[^]]*)?\][[:space:]]*(#.*)?$/)
2033
+ next
2034
+ }
2035
+ in_provider && match($0, /"?X-Weave-Router-Key"?[[:space:]]*=[[:space:]]*"[^"]*"/) {
1855
2036
  hdr = substr($0, RSTART, RLENGTH)
1856
2037
  sub(/^.*=[[:space:]]*"/, "", hdr)
1857
2038
  sub(/"$/, "", hdr)
@@ -2019,11 +2200,19 @@ resolve_installed_endpoint() {
2019
2200
  return 0
2020
2201
  ;;
2021
2202
  codex)
2203
+ # Read base_url from the [model_providers.weave] table wherever it sits,
2204
+ # not only from between the managed markers. Codex drops our comment
2205
+ # markers when it rewrites config.toml (see write_codex_config) while
2206
+ # keeping the table, and a marker-scoped read then reported a live
2207
+ # install as absent -- `login codex` and `status` claimed Codex was not
2208
+ # configured until the user re-installed to restore the markers.
2022
2209
  if key_source_is_own "$codex_config_file"; then
2023
- found="$(awk -v begin="$WEAVE_CODEX_BEGIN_MARKER" -v end="$WEAVE_CODEX_END_MARKER" '
2024
- $0 == begin { inblk = 1; next }
2025
- $0 == end { inblk = 0; next }
2026
- inblk && match($0, /^[[:space:]]*base_url[[:space:]]*=[[:space:]]*"[^"]*"/) {
2210
+ found="$(awk '
2211
+ /^[[:space:]]*\[/ {
2212
+ in_provider = ($0 ~ /^[[:space:]]*\[[[:space:]]*model_providers[[:space:]]*\.[[:space:]]*weave[[:space:]]*\][[:space:]]*(#.*)?$/)
2213
+ next
2214
+ }
2215
+ in_provider && match($0, /^[[:space:]]*base_url[[:space:]]*=[[:space:]]*"[^"]*"/) {
2027
2216
  line = substr($0, RSTART, RLENGTH)
2028
2217
  sub(/^.*=[[:space:]]*"/, "", line)
2029
2218
  sub(/"$/, "", line)
@@ -2947,6 +3136,12 @@ if [ "$mode" = "models" ] || [ "$mode" = "accounts" ] || [ "$mode" = "login" ] |
2947
3136
  # branches below so `set -u` holds on every path.
2948
3137
  models_base_source=""
2949
3138
  models_key_source=""
3139
+ # The codex fallback below and run_router_status both resolve a Codex install
3140
+ # even on a run whose target is Claude, and the per-target setup only defines
3141
+ # codex_config_file when the target IS codex. Default it here or `set -u`
3142
+ # aborts the whole command: `status` with a Codex-only install died on
3143
+ # "codex_config_file: unbound variable" instead of reporting the install.
3144
+ codex_config_file="${codex_config_file:-$settings_base/.codex/config.toml}"
2950
3145
  # Editing model selection needs the endpoint and key of one specific install,
2951
3146
  # never the hosted defaults: a self-hosted user pointing at their own router
2952
3147
  # would otherwise silently edit the hosted one's installation.
@@ -3507,6 +3702,26 @@ announce_done() {
3507
3702
  # latest known routed model in the terminal title. The embedded copy keeps the
3508
3703
  # standalone curl installer feature-complete; packaged installs use the
3509
3704
  # canonical sibling asset.
3705
+ # remove_codex_directive_helper deletes the UserPromptSubmit helper shipped in
3706
+ # 0.2.17. The router now answers those directives itself, so the hook is dead
3707
+ # weight — and a registration left pointing at a deleted script would make Codex
3708
+ # run a missing command on every prompt, so the two must go together.
3709
+ # strip_weave_codex_hooks removes the registration; this removes the file.
3710
+ remove_codex_directive_helper() {
3711
+ [ -e "$codex_directive_file" ] || return 0
3712
+ # Skip, do not exit: a symlink here is the user's, and aborting would leave
3713
+ # the install half-applied over something we were never going to touch.
3714
+ warn_if_symlink "$codex_directive_file" || return 0
3715
+ [ -f "$codex_directive_file" ] || return 0
3716
+ if grep -Fq '<!-- weave-router managed codex directive -->' "$codex_directive_file"; then
3717
+ rm -f "$codex_directive_file"
3718
+ ok "Removed the retired Codex directive hook at $codex_directive_file"
3719
+ rmdir "$(dirname "$codex_directive_file")" 2>/dev/null || true
3720
+ else
3721
+ warn "Leaving user-owned file at $codex_directive_file untouched."
3722
+ fi
3723
+ }
3724
+
3510
3725
  install_codex_status_script() {
3511
3726
  local candidate status_src=""
3512
3727
  for candidate in \
@@ -3630,11 +3845,6 @@ state_root="${XDG_CACHE_HOME:-$HOME/.cache}/weave-router/codex"
3630
3845
  helper_dir="$(cd "$(dirname "$0")" 2>/dev/null && pwd -P)"
3631
3846
  disabled_marker="$helper_dir/.weave-router-disabled"
3632
3847
  router_badge_sentinel=$'⁣⁠⁣⁠'
3633
- # Must stay verbatim in sync with install.sh / uninstall.sh: the endpoint read
3634
- # below is scoped to this block so a key-shaped string elsewhere in the user's
3635
- # config.toml is never adopted.
3636
- codex_begin_marker="# >>> weave-router managed (do not edit between markers) >>>"
3637
- codex_end_marker="# <<< weave-router managed <<<"
3638
3848
 
3639
3849
  emit_title() {
3640
3850
  local title="$1"
@@ -3694,10 +3904,18 @@ cost_file_for() {
3694
3904
  # Resolved from the helper's own location first so a project-scope install never
3695
3905
  # reads (or leaks) the user-scope key: the project helper lives in the same
3696
3906
  # .codex directory as its config, while the user-scope helper sits in ~/.weave
3697
- # and reads ~/.codex. Values are scoped to the managed block so a key-shaped
3698
- # string the user wrote elsewhere in the file is never adopted. awk, not a TOML
3699
- # parser, because the Codex target deliberately does not require jq for config
3700
- # reads.
3907
+ # and reads ~/.codex. Values are scoped to the [model_providers.weave] table so
3908
+ # a key-shaped string the user wrote elsewhere in the file is never adopted. awk,
3909
+ # not a TOML parser, because the Codex target deliberately does not require jq
3910
+ # for config reads.
3911
+ #
3912
+ # Scoped to the table rather than the managed comment markers, and matching the
3913
+ # header name quoted or bare, because Codex rewrites config.toml through a TOML
3914
+ # serializer whenever it persists its own state: comments do not survive, so the
3915
+ # markers vanish while the table remains, and the inline http_headers come back
3916
+ # as a subtable with the header name unquoted. A marker-scoped, quoted-only read
3917
+ # resolved nothing on any config Codex had touched, which silently dropped the
3918
+ # savings figure from the title with no error anywhere.
3701
3919
  read_codex_endpoint() {
3702
3920
  local config=""
3703
3921
  # Project/custom installs name the helper weave-status.sh and keep it next
@@ -3710,19 +3928,45 @@ read_codex_endpoint() {
3710
3928
  config="$HOME/.codex/config.toml"
3711
3929
  fi
3712
3930
  [ -n "$config" ] || return 0
3713
- awk -v begin="$codex_begin_marker" -v end="$codex_end_marker" '
3714
- $0 == begin { inblk = 1; next }
3715
- $0 == end { inblk = 0; next }
3716
- !inblk { next }
3931
+ awk '
3932
+ # Cut a TOML comment, honouring quoted strings so a # inside a value stays.
3933
+ # A full-line comment reduces to empty and matches nothing below, so this
3934
+ # replaces a separate skip rule -- and unlike one, it also catches a comment
3935
+ # trailing another assignment, which the unanchored matches would otherwise
3936
+ # read as live config on any line preceding the real value.
3937
+ function weave_strip_comment(line, i, c, out, indq, insq, esc) {
3938
+ out = ""
3939
+ indq = 0
3940
+ insq = 0
3941
+ esc = 0
3942
+ for (i = 1; i <= length(line); i++) {
3943
+ c = substr(line, i, 1)
3944
+ if (esc) { out = out c; esc = 0; continue }
3945
+ # Only basic strings have escapes; a backslash in a literal string is
3946
+ # data, so consuming the next character there would mis-track the quote.
3947
+ if (indq && c == "\\") { out = out c; esc = 1; continue }
3948
+ if (!insq && c == "\"") { indq = !indq; out = out c; continue }
3949
+ if (!indq && c == "'"'"'") { insq = !insq; out = out c; continue }
3950
+ if (c == "#" && !indq && !insq) break
3951
+ out = out c
3952
+ }
3953
+ return out
3954
+ }
3955
+ { $0 = weave_strip_comment($0) }
3956
+ /^[[:space:]]*\[/ {
3957
+ in_provider = ($0 ~ /^[[:space:]]*\[[[:space:]]*model_providers[[:space:]]*\.[[:space:]]*weave[[:space:]]*(\.[^]]*)?\][[:space:]]*(#.*)?$/)
3958
+ next
3959
+ }
3960
+ !in_provider { next }
3717
3961
  match($0, /base_url[[:space:]]*=[[:space:]]*"[^"]*"/) {
3718
3962
  v = substr($0, RSTART, RLENGTH)
3719
3963
  sub(/^.*=[[:space:]]*"/, "", v); sub(/"$/, "", v)
3720
- url = v
3964
+ if (url == "") url = v
3721
3965
  }
3722
- match($0, /"X-Weave-Router-Key"[[:space:]]*=[[:space:]]*"[^"]*"/) {
3966
+ match($0, /"?X-Weave-Router-Key"?[[:space:]]*=[[:space:]]*"[^"]*"/) {
3723
3967
  v = substr($0, RSTART, RLENGTH)
3724
3968
  sub(/^.*=[[:space:]]*"/, "", v); sub(/"$/, "", v)
3725
- key = v
3969
+ if (key == "") key = v
3726
3970
  }
3727
3971
  END { if (url != "" && key != "") printf "%s\n%s\n", url, key }
3728
3972
  ' "$config" 2>/dev/null || true
@@ -3920,6 +4164,7 @@ CODEX_STATUS_EOF
3920
4164
  ok "Codex status integration installed at $codex_status_file"
3921
4165
  }
3922
4166
 
4167
+
3923
4168
  if [ "$target" = "codex" ]; then
3924
4169
  if ! install_codex_status_script; then
3925
4170
  err "Cannot install the Codex status helper safely; refusing to write hooks that could execute unowned code."
@@ -3927,6 +4172,9 @@ if [ "$target" = "codex" ]; then
3927
4172
  fi
3928
4173
  write_codex_config "$codex_config_file" "$base_url" "$api_key" "$user_email" "$user_name"
3929
4174
  ok "Codex config written to $codex_config_file"
4175
+ # Only once the registration is gone: a helper deleted while its registration
4176
+ # survives makes Codex run a missing command on every prompt.
4177
+ remove_codex_directive_helper
3930
4178
  remove_obsolete_codex_prompt_wrappers "$codex_dir/prompts"
3931
4179
  install_codex_prompt_skills
3932
4180
  info "Codex router directives: begin the message with one space, e.g. ' /force-model gpt-5.6-terra'."
@@ -3941,6 +4189,7 @@ if [ "$target" = "codex" ]; then
3941
4189
  for entry in \
3942
4190
  ".codex/config.toml" \
3943
4191
  ".codex/weave-status.sh" \
4192
+ ".codex/weave-directive.sh" \
3944
4193
  ".codex/.weave-router-disabled"
3945
4194
  do
3946
4195
  if [ ! -f "$gitignore" ] || ! grep -qxF "$entry" "$gitignore"; then
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@weave-os/router",
3
- "version": "0.2.16",
3
+ "version": "0.2.18",
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",
package/uninstall.sh CHANGED
@@ -27,7 +27,6 @@ set -euo pipefail
27
27
  scope="user"
28
28
  scope_explicit="false"
29
29
  install_dir=""
30
- script_dir="$(cd "$(dirname "$0")" 2>/dev/null && pwd || true)"
31
30
 
32
31
  # ---------- directive registry (embedded) ----------
33
32
  #
@@ -45,7 +44,7 @@ router-feedback|rf|prompt|yes|yes|yes|no|manual|command,skill
45
44
  router-off||local-toggle|yes|yes|no|no|manual|command,skill
46
45
  router-on||local-toggle|yes|yes|no|no|manual|command,skill
47
46
  router-status||local-toggle|yes|yes|no|no|manual|command,skill
48
- router-session||prompt|yes|no|no|no|manual|command
47
+ router-session||prompt|yes|yes|no|no|manual|command,skill
49
48
  router-models|models|local-toggle|yes|yes|no|no|manual|command,skill
50
49
  disable-routing||local-toggle|no|yes|no|no|manual|skill
51
50
  beta||prompt|yes|no|no|yes|manual|command
@@ -206,11 +205,151 @@ fi
206
205
  WEAVE_CODEX_BEGIN_MARKER="# >>> weave-router managed (do not edit between markers) >>>"
207
206
  WEAVE_CODEX_END_MARKER="# <<< weave-router managed <<<"
208
207
 
209
- # strip_codex_block rewrites config.toml without the managed block and any
208
+ # strip_codex_block rewrites config.toml without the managed block, any
210
209
  # top-level `model_provider = "weave"` that lived outside the markers (which
211
- # can happen if the user copy-pasted our key into their own config). Other
212
- # top-level model_provider values are preserved so we don't yank a user back
213
- # into the OpenAI default when they meant to keep their own.
210
+ # can happen if the user copy-pasted our key into their own config), and any
211
+ # `[model_providers.weave]` table outside them. Other top-level model_provider
212
+ # values are preserved so we don't yank a user back into the OpenAI default
213
+ # when they meant to keep their own.
214
+ #
215
+ # The out-of-marker table has to go for the same reason install.sh strips it:
216
+ # Codex rewrites config.toml through a TOML serializer and our comment markers
217
+ # do not survive, so a marker-only uninstall reported success while leaving the
218
+ # provider -- and the router key inside it -- on disk.
219
+ # strip_weave_codex_hooks removes every hook registration this installer owns,
220
+ # matched by helper filename. Marker-scoped removal is not enough: Codex
221
+ # rewrites config.toml through a TOML serializer and our registrations often end
222
+ # up outside the markers, which used to leave them behind after an uninstall.
223
+ # Removal is per sub-entry so a group shared with a third party keeps theirs.
224
+ # Ownership contract for the Codex hook helpers. Every rule here was a bug
225
+ # first; keep them together so the next change has the whole set.
226
+ #
227
+ # 1. Ours is decided per path by that helper's EXACT marker. A prefix match
228
+ # lets the status marker vouch for the directive path, and the two
229
+ # deletion sites check exact markers -- so the strip would unwire a file
230
+ # it then declines to delete.
231
+ # 2. A missing file is ours. Its registration points at nothing, which is
232
+ # residue we left behind.
233
+ # 3. What a symlink means depends on the helper's lifecycle, so the caller
234
+ # says which it is.
235
+ # rewrite (status): the file is rewritten in place and never deleted, so
236
+ # the link is followed to read the marker. Disowning it instead leaves
237
+ # the old registrations while the managed block adds a fresh pair,
238
+ # stacking the duplicates this strip exists to remove.
239
+ # delete (directive): the file is removed, and removal refuses to act
240
+ # through a link. Claiming one would strip the registration and then
241
+ # decline the delete, leaving a helper Codex no longer runs -- rule 4
242
+ # violated in the one case it exists for.
243
+ # Either way the check precedes -e, which is false for a dangling link: it
244
+ # then fails the marker test and stays the user's, rather than being
245
+ # claimed by rule 2.
246
+ # 4. Registration and file must be decided together. Removing one while
247
+ # keeping the other leaves a script Codex never runs, with nothing on
248
+ # screen to explain it.
249
+ # 5. Compare decoded paths. The command value is a TOML basic string and the
250
+ # writer escapes it, so a raw comparison misses any path with a quote or
251
+ # backslash.
252
+ # warn_if_symlink reports a symlinked path and returns non-zero so the caller
253
+ # can skip just that file. refuse_if_symlink exits the process, which is right
254
+ # for a path we are about to write but wrong for these helpers: one symlinked
255
+ # helper would abort the whole run, stranding the config rewrite that is the
256
+ # actual work. Neither is deleted through a link either way.
257
+ warn_if_symlink() {
258
+ local target="$1"
259
+ [ -L "$target" ] || return 0
260
+ warn "$target is a symlink (-> $(readlink "$target")); leaving it untouched."
261
+ return 1
262
+ }
263
+
264
+ weave_owns_codex_helper() {
265
+ local path="$1" marker="$2" lifecycle="$3"
266
+ [ -n "$path" ] && [ -n "$marker" ] && [ -n "$lifecycle" ] || return 1
267
+ if [ -L "$path" ]; then
268
+ [ "$lifecycle" = "rewrite" ] || return 1
269
+ grep -Fq "$marker" "$path" 2>/dev/null
270
+ return $?
271
+ fi
272
+ [ -e "$path" ] || return 0
273
+ grep -Fq "$marker" "$path" 2>/dev/null
274
+ }
275
+
276
+ # weave_owned_codex_helpers prints, one per line, whichever of the two helper
277
+ # paths this installation may unwire.
278
+ weave_owned_codex_helpers() {
279
+ weave_owns_codex_helper "${codex_status_file:-}" '<!-- weave-router managed codex status -->' rewrite \
280
+ && printf '%s\n' "$codex_status_file"
281
+ weave_owns_codex_helper "${codex_directive_file:-}" '<!-- weave-router managed codex directive -->' delete \
282
+ && printf '%s\n' "$codex_directive_file"
283
+ return 0
284
+ }
285
+
286
+ strip_weave_codex_hooks() {
287
+ local config_file="$1"; shift
288
+ [ -f "$config_file" ] || return 0
289
+ # Exact paths, never a filename pattern: a third party's hook is free to be
290
+ # called weave-status.sh, and matching on the basename would delete it.
291
+ local owned="" candidate
292
+ for candidate in "$@"; do
293
+ [ -n "$candidate" ] || continue
294
+ # A unit separator, not a newline: BSD awk rejects an embedded newline in a
295
+ # -v value outright ("newline in string"), which silently disabled the whole
296
+ # pass on macOS.
297
+ owned="${owned}${candidate}$(printf '\037')"
298
+ done
299
+ [ -n "$owned" ] || return 0
300
+ local tmp; tmp="$(mktemp -t weave-codex-hooks.XXXXXX)"
301
+ awk -v owned="$owned" '
302
+ BEGIN {
303
+ n = split(owned, list, "\037")
304
+ for (i = 1; i <= n; i++) if (list[i] != "") own[list[i]] = 1
305
+ }
306
+ function flush_sub( i) {
307
+ if (sub_n == 0) return
308
+ if (!sub_is_weave) {
309
+ if (group_pending != "") {
310
+ print group_pending
311
+ group_pending = ""
312
+ if (group_blank) { print ""; group_blank = 0 }
313
+ }
314
+ for (i = 1; i <= sub_n; i++) print sub_line[i]
315
+ }
316
+ sub_n = 0
317
+ sub_is_weave = 0
318
+ }
319
+ function close_group() { flush_sub(); group_pending = ""; group_blank = 0 }
320
+ /^[[:space:]]*\[\[hooks\.[A-Za-z]+\.hooks\]\][[:space:]]*$/ {
321
+ flush_sub(); sub_n = 1; sub_line[1] = $0; next
322
+ }
323
+ /^[[:space:]]*\[\[hooks\.[A-Za-z]+\]\][[:space:]]*$/ {
324
+ close_group(); group_pending = $0; next
325
+ }
326
+ /^[[:space:]]*\[/ { close_group(); print; next }
327
+ {
328
+ if (sub_n > 0) {
329
+ sub_line[++sub_n] = $0
330
+ if (match($0, /^[[:space:]]*command[[:space:]]*=[[:space:]]*"([^"\\]|\\.)*"/)) {
331
+ v = substr($0, RSTART, RLENGTH)
332
+ sub(/^[^"]*"/, "", v); sub(/"$/, "", v)
333
+ # write_codex_config escapes the path before writing it, so undo that
334
+ # before comparing; quotes first, then backslashes.
335
+ gsub(/\\"/, "\"", v)
336
+ gsub(/\\\\/, "\\", v)
337
+ if (v in own) sub_is_weave = 1
338
+ }
339
+ next
340
+ }
341
+ if (group_pending != "" && $0 ~ /^[[:space:]]*$/) { group_blank = 1; next }
342
+ if (group_pending != "") {
343
+ print group_pending; group_pending = ""
344
+ if (group_blank) { print ""; group_blank = 0 }
345
+ }
346
+ print
347
+ }
348
+ END { close_group() }
349
+ ' "$config_file" >"$tmp" && mv "$tmp" "$config_file"
350
+ rm -f "$tmp" 2>/dev/null || true
351
+ }
352
+
214
353
  strip_codex_block() {
215
354
  local config_file="$1"
216
355
  local tmp; tmp="$(mktemp -t weave-codex-uninstall.XXXXXX)"
@@ -218,11 +357,26 @@ strip_codex_block() {
218
357
  $0 == begin { skip = 1; next }
219
358
  $0 == end { skip = 0; next }
220
359
  skip { next }
221
- /^[[:space:]]*\[/ { in_section = 1 }
360
+ /^[[:space:]]*\[/ {
361
+ in_section = 1
362
+ if ($0 ~ /^[[:space:]]*\[[[:space:]]*model_providers[[:space:]]*\.[[:space:]]*weave[[:space:]]*(\.[^]]*)?\][[:space:]]*(#.*)?$/) {
363
+ in_weave_provider = 1
364
+ next
365
+ }
366
+ in_weave_provider = 0
367
+ }
368
+ in_weave_provider { next }
222
369
  !in_section && /^[[:space:]]*model_provider[[:space:]]*=[[:space:]]*"weave"[[:space:]]*$/ { next }
223
370
  { print }
224
371
  ' "$config_file" >"$tmp"
225
372
  mv "$tmp" "$config_file"
373
+ local owned_helpers=()
374
+ while IFS= read -r owned_helper; do
375
+ [ -n "$owned_helper" ] && owned_helpers+=("$owned_helper")
376
+ done <<EOF
377
+ $(weave_owned_codex_helpers)
378
+ EOF
379
+ strip_weave_codex_hooks "$config_file" ${owned_helpers[@]+"${owned_helpers[@]}"}
226
380
  }
227
381
 
228
382
  # ---------- opencode uninstall path ----------
@@ -245,6 +399,9 @@ if [ "$target" = "opencode" ]; then
245
399
  printf "Project directory to uninstall from [default: %s]: " "$default_project_dir"
246
400
  read -r project_dir_choice </dev/tty || project_dir_choice=""
247
401
  project_dir="${project_dir_choice:-$default_project_dir}"
402
+ # Expand a leading ~ since `read` doesn't.
403
+ # The pattern intentionally matches a literal tilde.
404
+ # shellcheck disable=SC2088
248
405
  case "$project_dir" in
249
406
  "~") project_dir="$HOME" ;;
250
407
  "~/"*) project_dir="$HOME/${project_dir#~/}" ;;
@@ -395,6 +552,9 @@ if [ "$target" = "pi" ]; then
395
552
  printf "Project directory to uninstall from [default: %s]: " "$default_project_dir"
396
553
  read -r project_dir_choice </dev/tty || project_dir_choice=""
397
554
  project_dir="${project_dir_choice:-$default_project_dir}"
555
+ # Expand a leading ~ since `read` doesn't.
556
+ # The pattern intentionally matches a literal tilde.
557
+ # shellcheck disable=SC2088
398
558
  case "$project_dir" in
399
559
  "~") project_dir="$HOME" ;;
400
560
  "~/"*) project_dir="$HOME/${project_dir#~/}" ;;
@@ -501,6 +661,9 @@ if [ "$target" = "codex" ]; then
501
661
  printf "Project directory to uninstall from [default: %s]: " "$default_project_dir"
502
662
  read -r project_dir_choice </dev/tty || project_dir_choice=""
503
663
  project_dir="${project_dir_choice:-$default_project_dir}"
664
+ # Expand a leading ~ since `read` doesn't.
665
+ # The pattern intentionally matches a literal tilde.
666
+ # shellcheck disable=SC2088
504
667
  case "$project_dir" in
505
668
  "~") project_dir="$HOME" ;;
506
669
  "~/"*) project_dir="$HOME/${project_dir#~/}" ;;
@@ -525,13 +688,17 @@ if [ "$target" = "codex" ]; then
525
688
  codex_config_file="$codex_dir/config.toml"
526
689
  if [ "$scope" = "user" ] && [ -z "$install_dir" ]; then
527
690
  codex_status_file="$HOME/.weave/codex-status.sh"
691
+ codex_directive_file="$HOME/.weave/codex-directive.sh"
528
692
  else
529
693
  codex_status_file="$codex_dir/weave-status.sh"
694
+ codex_directive_file="$codex_dir/weave-directive.sh"
530
695
  fi
531
696
  codex_status_disabled_marker="$(dirname "$codex_status_file")/.weave-router-disabled"
532
697
  refuse_if_symlink "$codex_config_file"
533
- refuse_if_symlink "$codex_status_file"
534
698
  refuse_if_symlink "$codex_status_disabled_marker"
699
+ # The helpers are checked at their own removal sites instead. Refusing here
700
+ # exits before strip_codex_block, so one symlinked helper left the config
701
+ # wired to a router the uninstall had just been asked to remove.
535
702
 
536
703
  if [ -f "$codex_config_file" ]; then
537
704
  strip_codex_block "$codex_config_file"
@@ -556,7 +723,7 @@ if [ "$target" = "codex" ]; then
556
723
  mv "$tmp" "$codex_config_file"
557
724
  fi
558
725
 
559
- if [ -f "$codex_status_file" ]; then
726
+ if [ -f "$codex_status_file" ] && warn_if_symlink "$codex_status_file"; then
560
727
  if grep -Fq '<!-- weave-router managed codex status -->' "$codex_status_file"; then
561
728
  rm -f "$codex_status_file"
562
729
  rm -f "$codex_status_disabled_marker"
@@ -567,6 +734,16 @@ if [ "$target" = "codex" ]; then
567
734
  fi
568
735
  fi
569
736
 
737
+ if [ -f "$codex_directive_file" ] && warn_if_symlink "$codex_directive_file"; then
738
+ if grep -Fq '<!-- weave-router managed codex directive -->' "$codex_directive_file"; then
739
+ rm -f "$codex_directive_file"
740
+ ok "Removed $codex_directive_file"
741
+ rmdir "$(dirname "$codex_directive_file")" 2>/dev/null || true
742
+ else
743
+ warn "Leaving user-owned Codex directive helper at $codex_directive_file untouched."
744
+ fi
745
+ fi
746
+
570
747
  # Remove only the prompt files this installer owns; leave any user-authored
571
748
  # entries in prompts/ alone. The dir itself is dropped only if empty after.
572
749
  codex_prompts_dir="$codex_dir/prompts"
@@ -672,6 +849,9 @@ else
672
849
  printf "Project directory to uninstall from [default: %s]: " "$default_project_dir"
673
850
  read -r project_dir_choice </dev/tty || project_dir_choice=""
674
851
  project_dir="${project_dir_choice:-$default_project_dir}"
852
+ # Expand a leading ~ since `read` doesn't.
853
+ # The pattern intentionally matches a literal tilde.
854
+ # shellcheck disable=SC2088
675
855
  case "$project_dir" in
676
856
  "~") project_dir="$HOME" ;;
677
857
  "~/"*) project_dir="$HOME/${project_dir#~/}" ;;