@weave-os/router 0.2.15 → 0.2.17
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/cc-statusline.sh +18 -11
- package/codex-directive.sh +236 -0
- package/codex-skills/router-session/SKILL.md +27 -0
- package/codex-skills/router-session/scripts/emit.sh +17 -0
- package/codex-status.sh +45 -16
- package/directives.tsv +1 -1
- package/install.sh +602 -127
- package/package.json +2 -1
- package/pi-router/src/pricing.generated.ts +7 -6
- package/uninstall.sh +45 -7
package/cc-statusline.sh
CHANGED
|
@@ -234,8 +234,12 @@ weave_sync_commands() {
|
|
|
234
234
|
# be recovered those three are skipped rather than rewritten to point at the
|
|
235
235
|
# user-scope install.
|
|
236
236
|
local scope_args="" scope_known="false" off="$cmd_dir/router-off.md"
|
|
237
|
+
# Backticks are literal Markdown delimiters.
|
|
238
|
+
# shellcheck disable=SC2016
|
|
237
239
|
if [ -f "$off" ] && grep -Eq '^`npx @(workweave/router|weave-os/router) off --claude.*`$' "$off" 2>/dev/null; then
|
|
238
240
|
scope_known="true"
|
|
241
|
+
# Backticks are literal Markdown delimiters.
|
|
242
|
+
# shellcheck disable=SC2016
|
|
239
243
|
scope_args="$(sed -En 's#^`npx @(workweave/router|weave-os/router) off --claude(.*)`$#\2#p' "$off" | head -n 1)"
|
|
240
244
|
fi
|
|
241
245
|
|
|
@@ -274,7 +278,7 @@ weave_sync_commands() {
|
|
|
274
278
|
if [ -f "$prev" ]; then
|
|
275
279
|
new_body="$(weave_render_command "$raw" "$scope_args")"
|
|
276
280
|
prev_body="$(weave_render_command "$prev" "$scope_args")"
|
|
277
|
-
installed_body="$(
|
|
281
|
+
installed_body="$(sed '/^<!-- weave-router managed command: .* -->$/d' "$installed" 2>/dev/null)" || installed_body=""
|
|
278
282
|
if [ "$prev_body" = "$installed_body" ] && [ "$new_body" != "$installed_body" ]; then
|
|
279
283
|
tmp="$installed.tmp.$$"
|
|
280
284
|
if printf '%s\n<!-- weave-router managed command: %s -->' "$new_body" "$name" >"$tmp" 2>/dev/null; then
|
|
@@ -505,11 +509,12 @@ prices='{
|
|
|
505
509
|
"gpt-5.5-mini": 0.0005,
|
|
506
510
|
"gpt-5.5-nano": 0.00015,
|
|
507
511
|
"gpt-5.5-pro": 0.03,
|
|
508
|
-
"gpt-5.6-luna": 0.
|
|
509
|
-
"gpt-5.6-luna-pro": 0.
|
|
510
|
-
"gpt-5.6-sol": 0.
|
|
511
|
-
"gpt-5.6-sol-pro": 0.
|
|
512
|
-
"gpt-5.6-terra": 0.
|
|
512
|
+
"gpt-5.6-luna": 0.0002,
|
|
513
|
+
"gpt-5.6-luna-pro": 0.0002,
|
|
514
|
+
"gpt-5.6-sol": 0.004,
|
|
515
|
+
"gpt-5.6-sol-pro": 0.004,
|
|
516
|
+
"gpt-5.6-terra": 0.002,
|
|
517
|
+
"gpt-6-astra": 0.01,
|
|
513
518
|
"grok-4.5": 0.002,
|
|
514
519
|
"grok-4.6": 0.002,
|
|
515
520
|
"minimax/minimax-m2.7": 0.0003,
|
|
@@ -585,11 +590,12 @@ prices='{
|
|
|
585
590
|
"gpt-5.5-mini": 0.0025,
|
|
586
591
|
"gpt-5.5-nano": 0.0006,
|
|
587
592
|
"gpt-5.5-pro": 0.18,
|
|
588
|
-
"gpt-5.6-luna": 0.
|
|
589
|
-
"gpt-5.6-luna-pro": 0.
|
|
590
|
-
"gpt-5.6-sol": 0.
|
|
591
|
-
"gpt-5.6-sol-pro": 0.
|
|
592
|
-
"gpt-5.6-terra": 0.
|
|
593
|
+
"gpt-5.6-luna": 0.0012,
|
|
594
|
+
"gpt-5.6-luna-pro": 0.0012,
|
|
595
|
+
"gpt-5.6-sol": 0.02,
|
|
596
|
+
"gpt-5.6-sol-pro": 0.02,
|
|
597
|
+
"gpt-5.6-terra": 0.012,
|
|
598
|
+
"gpt-6-astra": 0.05,
|
|
593
599
|
"grok-4.5": 0.006,
|
|
594
600
|
"grok-4.6": 0.006,
|
|
595
601
|
"minimax/minimax-m2.7": 0.0012,
|
|
@@ -670,6 +676,7 @@ prices='{
|
|
|
670
676
|
"gpt-5.6-sol": 0.1,
|
|
671
677
|
"gpt-5.6-sol-pro": 0.1,
|
|
672
678
|
"gpt-5.6-terra": 0.1,
|
|
679
|
+
"gpt-6-astra": 0.1,
|
|
673
680
|
"grok-4.5": 0.25,
|
|
674
681
|
"grok-4.6": 0.25,
|
|
675
682
|
"minimax/minimax-m2.7": 0.2,
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# <!-- weave-router managed codex directive -->
|
|
3
|
+
#
|
|
4
|
+
# Codex UserPromptSubmit hook for the Weave Router. Codex passes a JSON object
|
|
5
|
+
# on stdin carrying the RAW prompt text, before `$skill` expansion and before
|
|
6
|
+
# any inference. That is what makes this hook the deterministic equivalent of
|
|
7
|
+
# Claude Code's slash commands.
|
|
8
|
+
#
|
|
9
|
+
# Why this exists. A Codex skill is prompt text: the model reads it, decides to
|
|
10
|
+
# exec a script, and invents the arguments. Pinning a model that way costs two
|
|
11
|
+
# inference turns (one to decide to run the script, one because the script's
|
|
12
|
+
# output arrives as a tool result) and loses argument fidelity — a `$rf - note`
|
|
13
|
+
# verdict is routinely paraphrased away by the model before it reaches the
|
|
14
|
+
# router. Claude Code pays neither cost, because `/fm x` is expanded textually
|
|
15
|
+
# by the client and the router short-circuits a user-typed directive into a
|
|
16
|
+
# synthetic response with no upstream call at all.
|
|
17
|
+
#
|
|
18
|
+
# This hook closes that gap. It parses the directive itself, sends it to the
|
|
19
|
+
# router as a user-typed message, and blocks the Codex turn — so the directive
|
|
20
|
+
# costs zero inference and the arguments arrive byte-for-byte.
|
|
21
|
+
#
|
|
22
|
+
# The pin lands on the caller's real session because the force-model pin key
|
|
23
|
+
# omits the first-message discriminator (see deriveForceModelSessionKeyForRequest):
|
|
24
|
+
# it is derived from the API key and the client session id alone, and this hook
|
|
25
|
+
# sends the same Session-Id that Codex sends on its own turns.
|
|
26
|
+
#
|
|
27
|
+
# FAIL OPEN. Every unexpected condition — no jq, no curl, no credentials, an
|
|
28
|
+
# unreachable router, a malformed payload — must let the prompt through
|
|
29
|
+
# untouched. A directive that silently swallows the user's prompt is far worse
|
|
30
|
+
# than one that does not fire.
|
|
31
|
+
|
|
32
|
+
set -uo pipefail
|
|
33
|
+
|
|
34
|
+
# ---------- responses ----------
|
|
35
|
+
|
|
36
|
+
# pass_through hands the prompt to Codex unchanged. Every failure path ends here.
|
|
37
|
+
pass_through() {
|
|
38
|
+
printf '{"continue":true}\n'
|
|
39
|
+
exit 0
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
# block stops the turn before any inference and shows the text to the user.
|
|
43
|
+
# Codex renders `reason`; nothing reaches the model.
|
|
44
|
+
block() {
|
|
45
|
+
local reason="$1" payload
|
|
46
|
+
payload="$(jq -cn --arg r "$reason" '{decision:"block", reason:$r, continue:false}' 2>/dev/null)" \
|
|
47
|
+
|| pass_through
|
|
48
|
+
printf '%s\n' "$payload"
|
|
49
|
+
exit 0
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
command -v jq >/dev/null 2>&1 || pass_through
|
|
53
|
+
|
|
54
|
+
payload="$(cat)" || pass_through
|
|
55
|
+
[ -n "$payload" ] || pass_through
|
|
56
|
+
|
|
57
|
+
prompt="$(jq -r '.prompt // ""' <<<"$payload" 2>/dev/null)" || pass_through
|
|
58
|
+
session_id="$(jq -r '.session_id // ""' <<<"$payload" 2>/dev/null)" || pass_through
|
|
59
|
+
requested_model="$(jq -r '.model // ""' <<<"$payload" 2>/dev/null)" || pass_through
|
|
60
|
+
|
|
61
|
+
# Only a directive at the very start of the prompt is ours. Prose that merely
|
|
62
|
+
# mentions `$fm` somewhere in a sentence is the user's text, not a command.
|
|
63
|
+
case "$prompt" in
|
|
64
|
+
'$'*) ;;
|
|
65
|
+
*) pass_through ;;
|
|
66
|
+
esac
|
|
67
|
+
|
|
68
|
+
verb="${prompt#$}"
|
|
69
|
+
args=""
|
|
70
|
+
case "$verb" in
|
|
71
|
+
*' '*)
|
|
72
|
+
args="${verb#* }"
|
|
73
|
+
verb="${verb%% *}"
|
|
74
|
+
;;
|
|
75
|
+
esac
|
|
76
|
+
# Trim surrounding whitespace from the argument tail without touching its
|
|
77
|
+
# interior: a leading `-`/`+` is a router-feedback verdict and must survive.
|
|
78
|
+
args="${args#"${args%%[![:space:]]*}"}"
|
|
79
|
+
args="${args%"${args##*[![:space:]]}"}"
|
|
80
|
+
|
|
81
|
+
# ---------- directive table ----------
|
|
82
|
+
#
|
|
83
|
+
# Only prompt-capability directives are handled here. The local-toggle skills
|
|
84
|
+
# (router-on/off/status/models, disable-routing) mutate local config rather than
|
|
85
|
+
# router state, so a skill remains the right adapter for them.
|
|
86
|
+
directive=""
|
|
87
|
+
case "$verb" in
|
|
88
|
+
fm|force-model) directive="/force-model" ;;
|
|
89
|
+
ufm|unforce-model) directive="/unforce-model" ;;
|
|
90
|
+
rf|router-feedback) directive="/router-feedback" ;;
|
|
91
|
+
router-session)
|
|
92
|
+
# Purely local: the session id is already in the hook payload, so this
|
|
93
|
+
# answers without a network call and without a model turn.
|
|
94
|
+
[ -n "$session_id" ] || pass_through
|
|
95
|
+
block "✦ Weave Router · session id: $session_id"
|
|
96
|
+
;;
|
|
97
|
+
*) pass_through ;;
|
|
98
|
+
esac
|
|
99
|
+
|
|
100
|
+
# A directive that needs an argument and has none is more useful as a prompt:
|
|
101
|
+
# the skill can still explain itself rather than the hook eating the message.
|
|
102
|
+
case "$directive" in
|
|
103
|
+
/force-model|/router-feedback)
|
|
104
|
+
[ -n "$args" ] || pass_through
|
|
105
|
+
;;
|
|
106
|
+
esac
|
|
107
|
+
|
|
108
|
+
# Without a client session id the router would derive a different pin key than
|
|
109
|
+
# Codex's own turns, so the pin would apply to a session the user is not in.
|
|
110
|
+
# Passing through is the honest failure: the skill path still works.
|
|
111
|
+
[ -n "$session_id" ] || pass_through
|
|
112
|
+
command -v curl >/dev/null 2>&1 || pass_through
|
|
113
|
+
|
|
114
|
+
# ---------- credentials ----------
|
|
115
|
+
#
|
|
116
|
+
# Read base_url and the router key from the [model_providers.weave] table.
|
|
117
|
+
# Deliberately NOT scoped to the managed comment markers: Codex rewrites
|
|
118
|
+
# config.toml through a TOML serializer when it persists its own state, which
|
|
119
|
+
# drops comments while keeping the table, and re-emits the inline http_headers
|
|
120
|
+
# as a subtable with the header name unquoted. A marker-scoped or quoted-only
|
|
121
|
+
# reader misses both on any config Codex has touched.
|
|
122
|
+
resolve_router_endpoint() {
|
|
123
|
+
local config=""
|
|
124
|
+
local helper_dir
|
|
125
|
+
helper_dir="$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" 2>/dev/null && pwd)" || helper_dir=""
|
|
126
|
+
if [ -n "$helper_dir" ] && [ -f "$helper_dir/config.toml" ]; then
|
|
127
|
+
config="$helper_dir/config.toml"
|
|
128
|
+
elif [ -f "${CODEX_HOME:-$HOME/.codex}/config.toml" ]; then
|
|
129
|
+
config="${CODEX_HOME:-$HOME/.codex}/config.toml"
|
|
130
|
+
fi
|
|
131
|
+
[ -n "$config" ] || return 1
|
|
132
|
+
awk '
|
|
133
|
+
# Cut a TOML comment, honouring quoted strings so a # inside a value stays.
|
|
134
|
+
# A full-line comment reduces to empty and matches nothing below, so this
|
|
135
|
+
# replaces a separate skip rule -- and unlike one, it also catches a comment
|
|
136
|
+
# trailing another assignment, which the unanchored matches would otherwise
|
|
137
|
+
# read as live config on any line preceding the real value.
|
|
138
|
+
function weave_strip_comment(line, i, c, out, indq, insq, esc) {
|
|
139
|
+
out = ""
|
|
140
|
+
indq = 0
|
|
141
|
+
insq = 0
|
|
142
|
+
esc = 0
|
|
143
|
+
for (i = 1; i <= length(line); i++) {
|
|
144
|
+
c = substr(line, i, 1)
|
|
145
|
+
if (esc) { out = out c; esc = 0; continue }
|
|
146
|
+
# Only basic strings have escapes; a backslash in a literal string is
|
|
147
|
+
# data, so consuming the next character there would mis-track the quote.
|
|
148
|
+
if (indq && c == "\\") { out = out c; esc = 1; continue }
|
|
149
|
+
if (!insq && c == "\"") { indq = !indq; out = out c; continue }
|
|
150
|
+
if (!indq && c == "'"'"'") { insq = !insq; out = out c; continue }
|
|
151
|
+
if (c == "#" && !indq && !insq) break
|
|
152
|
+
out = out c
|
|
153
|
+
}
|
|
154
|
+
return out
|
|
155
|
+
}
|
|
156
|
+
{ $0 = weave_strip_comment($0) }
|
|
157
|
+
# TOML basic string -> raw value: drop the `<header> = "` prefix and the
|
|
158
|
+
# closing quote, then undo the escaping write_codex_config applied.
|
|
159
|
+
function weave_unescape(s) {
|
|
160
|
+
sub(/^"?[A-Za-z][A-Za-z0-9-]*"?[[:space:]]*=[[:space:]]*"/, "", s)
|
|
161
|
+
sub(/"$/, "", s)
|
|
162
|
+
gsub(/\\"/, "\"", s)
|
|
163
|
+
gsub(/\\\\/, "\\", s)
|
|
164
|
+
return s
|
|
165
|
+
}
|
|
166
|
+
/^[[:space:]]*\[/ {
|
|
167
|
+
in_provider = ($0 ~ /^[[:space:]]*\[[[:space:]]*model_providers[[:space:]]*\.[[:space:]]*weave[[:space:]]*(\.[^]]*)?\][[:space:]]*(#.*)?$/)
|
|
168
|
+
next
|
|
169
|
+
}
|
|
170
|
+
!in_provider { next }
|
|
171
|
+
match($0, /base_url[[:space:]]*=[[:space:]]*"[^"]*"/) {
|
|
172
|
+
v = substr($0, RSTART, RLENGTH)
|
|
173
|
+
sub(/^.*=[[:space:]]*"/, "", v); sub(/"$/, "", v)
|
|
174
|
+
if (url == "") url = v
|
|
175
|
+
}
|
|
176
|
+
match($0, /"?X-Weave-Router-Key"?[[:space:]]*=[[:space:]]*"([^"\\]|\\.)*"/) {
|
|
177
|
+
if (key == "") key = weave_unescape(substr($0, RSTART, RLENGTH))
|
|
178
|
+
}
|
|
179
|
+
match($0, /"?X-Weave-User-Email"?[[:space:]]*=[[:space:]]*"([^"\\]|\\.)*"/) {
|
|
180
|
+
if (email == "") email = weave_unescape(substr($0, RSTART, RLENGTH))
|
|
181
|
+
}
|
|
182
|
+
match($0, /"?X-Weave-User-Name"?[[:space:]]*=[[:space:]]*"([^"\\]|\\.)*"/) {
|
|
183
|
+
if (name == "") name = weave_unescape(substr($0, RSTART, RLENGTH))
|
|
184
|
+
}
|
|
185
|
+
END { if (url != "" && key != "") printf "%s\n%s\n%s\n%s\n", url, key, email, name }
|
|
186
|
+
' "$config" 2>/dev/null
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
endpoint="$(resolve_router_endpoint)" || pass_through
|
|
190
|
+
base_url="$(printf '%s' "$endpoint" | sed -n 1p)"
|
|
191
|
+
router_key="$(printf '%s' "$endpoint" | sed -n 2p)"
|
|
192
|
+
user_email="$(printf '%s' "$endpoint" | sed -n 3p)"
|
|
193
|
+
user_name="$(printf '%s' "$endpoint" | sed -n 4p)"
|
|
194
|
+
if [ -z "$base_url" ] || [ -z "$router_key" ]; then
|
|
195
|
+
pass_through
|
|
196
|
+
fi
|
|
197
|
+
|
|
198
|
+
url="${base_url%/}"
|
|
199
|
+
url="${url%/v1}/v1/chat/completions"
|
|
200
|
+
|
|
201
|
+
# ---------- send ----------
|
|
202
|
+
#
|
|
203
|
+
# The leading space is what stops Codex's own slash-command handling from
|
|
204
|
+
# claiming the line; the router strips it. Sent as a user message (not a tool
|
|
205
|
+
# result) so the router takes its synthetic short-circuit and never calls a
|
|
206
|
+
# model — the same path Claude Code's slash commands already take.
|
|
207
|
+
line=" $directive"
|
|
208
|
+
[ -n "$args" ] && line="$line $args"
|
|
209
|
+
|
|
210
|
+
body="$(jq -cn --arg m "${requested_model:-gpt-5.6-sol}" --arg c "$line" \
|
|
211
|
+
'{model:$m, messages:[{role:"user", content:$c}]}' 2>/dev/null)" || pass_through
|
|
212
|
+
|
|
213
|
+
# Identity headers only when the install has them: the router must never see a
|
|
214
|
+
# header with an empty value, and omitting them is what an unattributed install
|
|
215
|
+
# already does on every ordinary turn.
|
|
216
|
+
identity_args=()
|
|
217
|
+
[ -n "$user_email" ] && identity_args+=(-H "X-Weave-User-Email: $user_email")
|
|
218
|
+
[ -n "$user_name" ] && identity_args+=(-H "X-Weave-User-Name: $user_name")
|
|
219
|
+
|
|
220
|
+
response="$(curl -fsS --max-time 10 \
|
|
221
|
+
-H "Content-Type: application/json" \
|
|
222
|
+
-H "X-Weave-Router-Key: $router_key" \
|
|
223
|
+
-H "Session-Id: $session_id" \
|
|
224
|
+
-H "X-App: codex" \
|
|
225
|
+
${identity_args[@]+"${identity_args[@]}"} \
|
|
226
|
+
-d "$body" \
|
|
227
|
+
"$url" 2>/dev/null)" || pass_through
|
|
228
|
+
[ -n "$response" ] || pass_through
|
|
229
|
+
|
|
230
|
+
# `strings` filters to the string type: jq -r would otherwise render an object
|
|
231
|
+
# or array as JSON, which is non-empty and would block the turn with garbage.
|
|
232
|
+
marker="$(jq -r '[.choices[0].message.content | strings] | first // ""' <<<"$response" 2>/dev/null)" || pass_through
|
|
233
|
+
marker="$(printf '%s' "$marker" | sed -e 's/\*\*//g' -e '/^[[:space:]]*$/d')"
|
|
234
|
+
[ -n "$marker" ] || pass_through
|
|
235
|
+
|
|
236
|
+
block "$marker"
|
|
@@ -0,0 +1,27 @@
|
|
|
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
|
+
The Weave Router also installs a `UserPromptSubmit` hook that answers
|
|
20
|
+
`$router-session` directly, with no model turn at all — that is the normal path,
|
|
21
|
+
and it works whether or not this skill runs.
|
|
22
|
+
|
|
23
|
+
This skill is only the fallback for sessions where the hook is unavailable, and it
|
|
24
|
+
needs `CODEX_SESSION_ID` in the environment. If that is unset the script exits
|
|
25
|
+
non-zero rather than reporting an id: the alternative is reading the newest rollout
|
|
26
|
+
transcript, which names a different session whenever two run at once. Report the
|
|
27
|
+
error as-is instead of guessing an id.
|
|
@@ -0,0 +1,17 @@
|
|
|
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 "The Weave Router's UserPromptSubmit hook answers \$router-session directly" >&2
|
|
16
|
+
echo "from the session id Codex gives it; re-run the installer to enable it." >&2
|
|
17
|
+
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
|
|
161
|
-
# string the user wrote elsewhere in the file is never adopted. awk,
|
|
162
|
-
# parser, because the Codex target deliberately does not require jq
|
|
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
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
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|
|
|
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
|