@weave-os/router 0.2.20 → 0.2.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -7,7 +7,7 @@ published as a compatibility alias and continues to receive the same releases;
7
7
  it prints a migration warning directing users to `@weave-os/router`.
8
8
 
9
9
  ```bash
10
- npx @weave-os/router # interactive: pick Claude Code / Codex / opencode / pi, then scope
10
+ npx @weave-os/router # open the hosted setup page
11
11
  npx @weave-os/router --claude # skip the picker, target Claude Code
12
12
  npx @weave-os/router --codex # skip the picker, target the OpenAI Codex CLI
13
13
  npx @weave-os/router setup --claude --codex # configure both native clients
@@ -24,26 +24,6 @@ npx @weave-os/router --email you@example.com # set identity without prompting
24
24
  npx @weave-os/router --non-interactive # reads $WEAVE_ROUTER_KEY, no prompts (defaults to claude)
25
25
  ```
26
26
 
27
- Re-running the installer to pick up changes reuses the key already on disk, so
28
- you paste it once and never again — for every client, not just Claude Code.
29
- `update` is the never-prompting form of that (safe for cron; errors instead of
30
- asking when no key can be found):
31
-
32
- ```bash
33
- npx @weave-os/router --claude # reuses the installed key
34
- npx @weave-os/router --codex # same for Codex, opencode, and pi
35
- npx @weave-os/router --claude --rotate-key # ignore it and prompt for a new one
36
- npx @weave-os/router update --claude # non-interactive refresh in place
37
- npx @weave-os/router update --claude --context-window 1m # opt into Claude's 1M local context
38
- ```
39
-
40
- Claude Code normally keeps a 200k local context budget when using a custom
41
- router endpoint. The explicit `--context-window 1m` option selects the
42
- supported `[1m]` model variant, preserves automatic compaction, and records
43
- the prior model so `off` or uninstall can restore it. It is opt-in: longer
44
- histories can increase token usage and cost, and the upstream provider still
45
- needs to support the requested context size.
46
-
47
27
  For Claude Code the installed statusline and `/force-model`, `/router-*` slash
48
28
  commands also refresh themselves in the background about once a week (never
49
29
  overwriting a wrapper you edited). Opt out with `WEAVE_STATUSLINE_UPDATE=0`, or
package/bin.js CHANGED
@@ -1,7 +1,6 @@
1
1
  #!/usr/bin/env node
2
- // Thin wrapper that runs install.sh with the user's arguments.
3
- // Bundled install.sh ships with the npm package so `npx @weave-os/router`
4
- // works offline (modulo the router API ping the installer does).
2
+ // Thin wrapper that runs install.sh with the user's arguments. The canonical
3
+ // no-argument command opens the hosted setup page instead.
5
4
 
6
5
  const { spawnSync } = require("node:child_process");
7
6
  const { existsSync, readFileSync } = require("node:fs");
@@ -12,6 +11,13 @@ const packageName = JSON.parse(
12
11
  readFileSync(path.join(__dirname, "package.json"), "utf8"),
13
12
  ).name;
14
13
 
14
+ const defaultEntrypointURL = "https://router.workweave.ai/start";
15
+
16
+ if (packageName === "@weave-os/router" && args.length === 0) {
17
+ openDefaultEntrypoint(defaultEntrypointURL);
18
+ process.exit(0);
19
+ }
20
+
15
21
  if (packageName === "@workweave/router") {
16
22
  console.error(
17
23
  "warning: @workweave/router is deprecated; use @weave-os/router instead (npx @weave-os/router).",
@@ -66,3 +72,15 @@ function pickBash() {
66
72
  }
67
73
  return null;
68
74
  }
75
+
76
+ function openDefaultEntrypoint(url) {
77
+ const opener = process.platform === "darwin"
78
+ ? ["open", [url]]
79
+ : process.platform === "win32"
80
+ ? ["cmd.exe", ["/c", "start", "", url]]
81
+ : ["xdg-open", [url]];
82
+ const result = spawnSync(opener[0], opener[1], { stdio: "ignore" });
83
+ if (result.error || result.status !== 0) {
84
+ console.log(`Open ${url} in your browser to get started.`);
85
+ }
86
+ }
package/cc-statusline.sh CHANGED
@@ -522,6 +522,7 @@ prices='{
522
522
  "gpt-6-astra": 0.01,
523
523
  "grok-4.5": 0.002,
524
524
  "grok-4.6": 0.002,
525
+ "grok-4.7": 0.002,
525
526
  "minimax/minimax-m2.7": 0.0003,
526
527
  "minimax/minimax-m3": 0.0003,
527
528
  "mistralai/mistral-small-2603": 0.0002,
@@ -603,6 +604,7 @@ prices='{
603
604
  "gpt-6-astra": 0.05,
604
605
  "grok-4.5": 0.006,
605
606
  "grok-4.6": 0.006,
607
+ "grok-4.7": 0.006,
606
608
  "minimax/minimax-m2.7": 0.0012,
607
609
  "minimax/minimax-m3": 0.0012,
608
610
  "mistralai/mistral-small-2603": 0.0006,
@@ -684,6 +686,7 @@ prices='{
684
686
  "gpt-6-astra": 0.1,
685
687
  "grok-4.5": 0.25,
686
688
  "grok-4.6": 0.25,
689
+ "grok-4.7": 0.25,
687
690
  "minimax/minimax-m2.7": 0.2,
688
691
  "minimax/minimax-m3": 0.2,
689
692
  "mistralai/mistral-small-2603": 0.1,
package/install.sh CHANGED
@@ -1178,7 +1178,8 @@ write_pi_models_config() {
1178
1178
  { id: "gpt-6-astra", name: "GPT-6 Astra (via Weave Router)", reasoning: true, input: ["text","image"], contextWindow: 1050000, maxTokens: 128000 },
1179
1179
  { id: "gpt-5.6-sol", name: "GPT-5.6 Sol (via Weave Router)", reasoning: true, input: ["text","image"], contextWindow: 1050000, maxTokens: 128000 },
1180
1180
  { id: "grok-4.5", name: "Grok 4.5 (via Weave Router)", reasoning: true, input: ["text","image"], contextWindow: 500000, maxTokens: 131072 },
1181
- { id: "grok-4.6", name: "Grok 4.6 (via Weave Router)", reasoning: true, input: ["text","image"], contextWindow: 500000, maxTokens: 131072 }
1181
+ { id: "grok-4.6", name: "Grok 4.6 (via Weave Router)", reasoning: true, input: ["text","image"], contextWindow: 500000, maxTokens: 131072 },
1182
+ { id: "grok-4.7", name: "Grok 4.7 (via Weave Router)", reasoning: true, input: ["text","image"], contextWindow: 500000, maxTokens: 131072 }
1182
1183
  ]
1183
1184
  }
1184
1185
  ')"
@@ -1640,10 +1641,12 @@ fi
1640
1641
 
1641
1642
  # ---------- interactive scope prompt ----------
1642
1643
 
1643
- # If the user didn't pass --scope and we have a controlling terminal, ask which
1644
- # scope to install into. Non-interactive runs (CI, `curl | sh --non-interactive`)
1644
+ # If the user is installing and didn't pass --scope, ask which scope to write
1645
+ # into. Account, status, and model commands only read an existing install, so
1646
+ # they keep the user-scope default unless the caller explicitly selects a
1647
+ # project scope. Non-interactive installs (CI, `curl | sh --non-interactive`)
1645
1648
  # silently use the "user" default.
1646
- if [ -z "$install_dir" ] && [ "$scope_explicit" = "false" ] && [ "$non_interactive" = "false" ] && [ -r /dev/tty ]; then
1649
+ if [ "$mode" = "install" ] && [ -z "$install_dir" ] && [ "$scope_explicit" = "false" ] && [ "$non_interactive" = "false" ] && [ -r /dev/tty ]; then
1647
1650
  # Per-target paths so the prompt text matches what actually gets written.
1648
1651
  case "$target" in
1649
1652
  codex)
@@ -3156,7 +3159,7 @@ run_accounts() {
3156
3159
  if [ "$models_json" = "true" ]; then
3157
3160
  printf '%s\n' "$models_http_body"
3158
3161
  else
3159
- printf '%s\n' "$models_http_body" | jq -r '.[] | "\(.id)\t\(.provider)\t\(.external_account_id)\t\(if .enabled then "enabled" else "disabled" end)\t\(if .cooldown_until then "cooldown until " + .cooldown_until else "ready" end)"'
3162
+ printf '%s\n' "$models_http_body" | jq -r '.[] | "\(.id)\t\(.provider)\t\(.external_account_id)" + (if (.display_name // "") != "" then "\t" + .display_name else "" end) + "\t" + (if .enabled then "enabled" else "disabled" end) + "\t" + (if .cooldown_until then "cooldown until " + .cooldown_until else "ready" end)'
3160
3163
  fi
3161
3164
  ;;
3162
3165
  disable|remove)
@@ -3201,6 +3204,24 @@ jwt_account_id() {
3201
3204
  printf '%s' "$decoded" | jq -r '.chatgpt_account_id // .["https://api.openai.com/auth"].chatgpt_account_id // .organizations[0].id // empty' 2>/dev/null || true
3202
3205
  }
3203
3206
 
3207
+ jwt_account_label() {
3208
+ local token="$1" payload padding decoded
3209
+ payload="$(printf '%s' "$token" | cut -d. -f2 | tr '_-' '/+')"
3210
+ padding=$(( (4 - ${#payload} % 4) % 4 ))
3211
+ while [ "$padding" -gt 0 ]; do payload="${payload}="; padding=$((padding - 1)); done
3212
+ decoded="$(printf '%s' "$payload" | base64 --decode 2>/dev/null || printf '%s' "$payload" | base64 -D 2>/dev/null || true)"
3213
+ printf '%s' "$decoded" | jq -r '
3214
+ def clean: if type == "string" then gsub("[[:cntrl:]]"; " ") | gsub("[[:space:]]+"; " ") | sub("^ +"; "") | sub(" +$"; "") else "" end;
3215
+ (.organizations[0].name // .organizations[0].display_name // .organization.name // "" | clean) as $organization |
3216
+ (.email // .email_address // .["https://api.openai.com/profile"].email // .["https://api.openai.com/auth"].email // "" | clean) as $email |
3217
+ (.name // .preferred_username // "" | clean) as $name |
3218
+ if $organization != "" and $email != "" then ($organization + ": " + $email)
3219
+ elif $email != "" then $email
3220
+ elif $organization != "" then $organization
3221
+ else $name end
3222
+ ' 2>/dev/null || true
3223
+ }
3224
+
3204
3225
  # OAuth issuers rate-limit curl's default user agent, which fails the token
3205
3226
  # exchange (and every later refresh) with a 429 before the request is even
3206
3227
  # read, so identify the installer explicitly.
@@ -3229,7 +3250,7 @@ oauth_post_form() {
3229
3250
  }
3230
3251
 
3231
3252
  run_login_claude() {
3232
- local verifier challenge expected_state authorize_endpoint authorize_url pasted_code auth_code returned_state token_response refresh_token external_account_id body
3253
+ local verifier challenge expected_state authorize_endpoint authorize_url pasted_code auth_code returned_state token_response refresh_token account_uuid organization_uuid account_email organization_name display_name external_account_id body
3233
3254
  verifier="$(openssl rand 32 | oauth_base64url)"
3234
3255
  challenge="$(printf '%s' "$verifier" | openssl dgst -sha256 -binary | oauth_base64url)"
3235
3256
  expected_state="$(openssl rand 32 | oauth_base64url)"
@@ -3251,14 +3272,27 @@ run_login_claude() {
3251
3272
  || { err "Claude token exchange failed."; exit 1; }
3252
3273
  refresh_token="$(printf '%s' "$token_response" | jq -r '.refresh_token // empty')"
3253
3274
  [ -n "$refresh_token" ] || { err "Claude token exchange returned no refresh token."; exit 1; }
3254
- external_account_id="claude-$(openssl rand 12 | oauth_base64url)"
3255
- body="$(jq -nc --arg provider claude --arg account "$external_account_id" --arg token "$refresh_token" '{provider:$provider,external_account_id:$account,refresh_token:$token}')"
3275
+ account_uuid="$(printf '%s' "$token_response" | jq -er '.account.uuid | select(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}$")) | ascii_downcase' 2>/dev/null)" \
3276
+ || { err "Claude token exchange returned no valid account UUID; subscription was not enrolled. Update the installer and try again."; exit 1; }
3277
+ organization_uuid="$(printf '%s' "$token_response" | jq -er '.organization.uuid | select(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}$")) | ascii_downcase' 2>/dev/null)" \
3278
+ || { err "Claude token exchange returned no valid organization UUID; subscription was not enrolled. Update the installer and try again."; exit 1; }
3279
+ account_email="$(printf '%s' "$token_response" | jq -r '.account.email_address // .account.email // empty' 2>/dev/null || true)"
3280
+ organization_name="$(printf '%s' "$token_response" | jq -r '.organization.name // .organization.display_name // empty' 2>/dev/null || true)"
3281
+ display_name="$(jq -nr --arg organization "$organization_name" --arg email "$account_email" '
3282
+ def clean: gsub("[[:cntrl:]]"; " ") | gsub("[[:space:]]+"; " ") | sub("^ +"; "") | sub(" +$"; "");
3283
+ ($organization | clean) as $organization | ($email | clean) as $email |
3284
+ if $organization != "" and $email != "" then ($organization + ": " + $email)
3285
+ elif $email != "" then $email
3286
+ else $organization end
3287
+ ')"
3288
+ external_account_id="${account_uuid}:${organization_uuid}"
3289
+ body="$(jq -nc --arg provider claude --arg account "$external_account_id" --arg token "$refresh_token" --arg label "$display_name" '{provider:$provider,external_account_id:$account,refresh_token:$token} | if $label != "" then .display_name = $label else . end')"
3256
3290
  models_api POST "/v1/subscriptions/accounts" "$body" || models_fail "enrolling Claude subscription"
3257
3291
  ok "Claude subscription enrolled."
3258
3292
  }
3259
3293
 
3260
3294
  run_login_codex() {
3261
- local issuer device_response device_auth_id user_code interval authorization_response authorization_code verifier token_response refresh_token account_id body attempts token_form
3295
+ local issuer device_response device_auth_id user_code interval authorization_response authorization_code verifier token_response refresh_token account_id display_name identity_token body attempts token_form
3262
3296
  issuer="${WEAVE_CODEX_OAUTH_ISSUER:-https://auth.openai.com}"
3263
3297
  device_response="$(oauth_post_json "$issuer/api/accounts/deviceauth/usercode" '{"client_id":"app_EMoamEEZ73f0CkXaXp7hrann"}')" \
3264
3298
  || { err "Could not start Codex device authorization."; exit 1; }
@@ -3291,12 +3325,14 @@ run_login_codex() {
3291
3325
  token_response="$(oauth_post_form "$issuer/oauth/token" "$token_form")" \
3292
3326
  || { err "Codex token exchange failed."; exit 1; }
3293
3327
  refresh_token="$(printf '%s' "$token_response" | jq -r '.refresh_token // empty')"
3294
- account_id="$(jwt_account_id "$(printf '%s' "$token_response" | jq -r '.id_token // .access_token // empty')")"
3328
+ identity_token="$(printf '%s' "$token_response" | jq -r '.id_token // .access_token // empty')"
3329
+ account_id="$(jwt_account_id "$identity_token")"
3330
+ display_name="$(jwt_account_label "$identity_token")"
3295
3331
  if [ -z "$refresh_token" ] || [ -z "$account_id" ]; then
3296
3332
  err "Codex token exchange omitted account identity or refresh credentials."
3297
3333
  exit 1
3298
3334
  fi
3299
- body="$(jq -nc --arg provider codex --arg account "$account_id" --arg token "$refresh_token" '{provider:$provider,external_account_id:$account,refresh_token:$token}')"
3335
+ body="$(jq -nc --arg provider codex --arg account "$account_id" --arg token "$refresh_token" --arg label "$display_name" '{provider:$provider,external_account_id:$account,refresh_token:$token} | if $label != "" then .display_name = $label else . end')"
3300
3336
  models_api POST "/v1/subscriptions/accounts" "$body" || models_fail "enrolling Codex subscription"
3301
3337
  ok "Codex subscription enrolled."
3302
3338
  }
@@ -3348,7 +3384,7 @@ run_router_status() {
3348
3384
  if [ "$(printf '%s' "$models_http_body" | jq 'length')" -eq 0 ]; then
3349
3385
  printf ' none enrolled\n'
3350
3386
  else
3351
- printf '%s\n' "$models_http_body" | jq -r '.[] | " " + .provider + " " + .external_account_id + " " + (if .enabled then "enabled" else "disabled" end) + (if .cooldown_until then " cooldown until " + .cooldown_until else " ready" end)'
3387
+ printf '%s\n' "$models_http_body" | jq -r '.[] | " " + .provider + " " + .external_account_id + (if (.display_name // "") != "" then " [" + .display_name + "]" else "" end) + " " + (if .enabled then "enabled" else "disabled" end) + (if .cooldown_until then " cooldown until " + .cooldown_until else " ready" end)'
3352
3388
  fi
3353
3389
  elif [ "$models_http_status" = "404" ]; then
3354
3390
  printf 'Subscription accounts: server-side pools disabled\n'
@@ -5378,6 +5414,7 @@ prices='{
5378
5414
  "gpt-6-astra": 0.01,
5379
5415
  "grok-4.5": 0.002,
5380
5416
  "grok-4.6": 0.002,
5417
+ "grok-4.7": 0.002,
5381
5418
  "minimax/minimax-m2.7": 0.0003,
5382
5419
  "minimax/minimax-m3": 0.0003,
5383
5420
  "mistralai/mistral-small-2603": 0.0002,
@@ -5459,6 +5496,7 @@ prices='{
5459
5496
  "gpt-6-astra": 0.05,
5460
5497
  "grok-4.5": 0.006,
5461
5498
  "grok-4.6": 0.006,
5499
+ "grok-4.7": 0.006,
5462
5500
  "minimax/minimax-m2.7": 0.0012,
5463
5501
  "minimax/minimax-m3": 0.0012,
5464
5502
  "mistralai/mistral-small-2603": 0.0006,
@@ -5540,6 +5578,7 @@ prices='{
5540
5578
  "gpt-6-astra": 0.1,
5541
5579
  "grok-4.5": 0.25,
5542
5580
  "grok-4.6": 0.25,
5581
+ "grok-4.7": 0.25,
5543
5582
  "minimax/minimax-m2.7": 0.2,
5544
5583
  "minimax/minimax-m3": 0.2,
5545
5584
  "mistralai/mistral-small-2603": 0.1,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@weave-os/router",
3
- "version": "0.2.20",
3
+ "version": "0.2.22",
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",
@@ -0,0 +1,119 @@
1
+ import { randomUUID } from "node:crypto";
2
+ import { VERSION, type ExtensionAPI, type ExtensionContext } from "@mariozechner/pi-coding-agent";
3
+ import { getRole, getRouterBaseUrl, PROVIDER_NAME, providerHeaders, resolveRouterKey } from "./config.js";
4
+
5
+ const ENTRY_TYPE = "weave-classifier-thread";
6
+ const THREAD_FIELD = "weave_classifier_thread";
7
+
8
+ interface ClassifierThread {
9
+ sessionId: string;
10
+ routerOrigin: string;
11
+ newChatId: string;
12
+ threadToken?: string;
13
+ }
14
+
15
+ function isRecord(value: unknown): value is Record<string, unknown> {
16
+ return value !== null && typeof value === "object" && !Array.isArray(value);
17
+ }
18
+
19
+ function notify(ctx: ExtensionContext, message: string) {
20
+ if (ctx.hasUI) ctx.ui.notify(message, "error");
21
+ else process.stderr.write(`${message}\n`);
22
+ }
23
+
24
+ /** Enroll only explicit new sessions; a persisted attempt cannot silently become legacy traffic. */
25
+ export function registerClassifierThread(pi: ExtensionAPI, request: typeof fetch = fetch, version = VERSION): () => boolean {
26
+ let thread: ClassifierThread | undefined;
27
+ let pending: Promise<void> | undefined;
28
+ let generation = 0;
29
+ const [major, minor] = version.split(".").map(Number);
30
+ const supported = major > 0 || (major === 0 && minor >= 83);
31
+
32
+ const restore = (ctx: ExtensionContext) => {
33
+ generation++;
34
+ pending = undefined;
35
+ thread = undefined;
36
+ // All entries, not just the active branch: tree navigation must not erase enrollment.
37
+ for (const entry of ctx.sessionManager.getEntries()) {
38
+ if (entry.type !== "custom" || entry.customType !== ENTRY_TYPE || !isRecord(entry.data)) continue;
39
+ const saved = entry.data;
40
+ if (saved.sessionId !== ctx.sessionManager.getSessionId()) continue;
41
+ if (typeof saved.routerOrigin !== "string" || typeof saved.newChatId !== "string" ||
42
+ (saved.threadToken !== undefined && typeof saved.threadToken !== "string")) {
43
+ thread = { sessionId: ctx.sessionManager.getSessionId(), routerOrigin: "", newChatId: "" };
44
+ return;
45
+ }
46
+ thread = { sessionId: saved.sessionId, routerOrigin: saved.routerOrigin, newChatId: saved.newChatId, threadToken: saved.threadToken };
47
+ }
48
+ };
49
+
50
+ const ensureTicket = async (ctx: ExtensionContext) => {
51
+ if (!thread) return;
52
+ if (thread.sessionId !== ctx.sessionManager.getSessionId() || thread.routerOrigin !== getRouterBaseUrl()) {
53
+ throw new Error("Classifier session or router changed; start a new chat");
54
+ }
55
+ if (thread.threadToken) return;
56
+ if (pending) return pending;
57
+ const enrollment = thread;
58
+ const requestGeneration = generation;
59
+ pending = (async () => {
60
+ const routerKey = resolveRouterKey();
61
+ if (!routerKey) throw new Error("Router key is missing");
62
+ const signals = [AbortSignal.timeout(10_000)];
63
+ if (ctx.signal) signals.push(ctx.signal);
64
+ const response = await request(`${enrollment.routerOrigin}/v1/router/threads`, {
65
+ method: "POST", redirect: "error",
66
+ headers: { ...providerHeaders(getRole(), routerKey), "content-type": "application/json" },
67
+ body: JSON.stringify({ new_chat_id: enrollment.newChatId }), signal: AbortSignal.any(signals),
68
+ });
69
+ if (!response.ok) throw new Error(`Classifier enrollment returned HTTP ${response.status}`);
70
+ const ticket: unknown = await response.json();
71
+ if (!isRecord(ticket) || typeof ticket.thread_token !== "string" || !ticket.thread_token || ticket.thread_token.length > 4096) {
72
+ throw new Error("Invalid classifier enrollment response");
73
+ }
74
+ if (generation !== requestGeneration || ctx.signal?.aborted) throw new Error("Session changed during classifier enrollment");
75
+ enrollment.threadToken = ticket.thread_token;
76
+ pi.appendEntry(ENTRY_TYPE, { ...enrollment });
77
+ })();
78
+ try { await pending; } finally { if (generation === requestGeneration) pending = undefined; }
79
+ };
80
+
81
+ pi.on("session_start", async (event, ctx) => {
82
+ restore(ctx);
83
+ if (!thread && process.env.WEAVE_PI_LLM_CLASSIFIER === "1" && supported &&
84
+ ctx.model?.provider === PROVIDER_NAME && (event.reason === "new" || event.reason === "startup") &&
85
+ !ctx.sessionManager.getHeader()?.parentSession &&
86
+ !ctx.sessionManager.getEntries().some(entry => entry.type === "message" || entry.type === "compaction" || entry.type === "branch_summary")) {
87
+ thread = { sessionId: ctx.sessionManager.getSessionId(), routerOrigin: getRouterBaseUrl(), newChatId: randomUUID() };
88
+ // Persist before I/O so a crash/retry cannot create another server thread.
89
+ pi.appendEntry(ENTRY_TYPE, { ...thread });
90
+ }
91
+ try { await ensureTicket(ctx); } catch {
92
+ notify(ctx, "Classifier enrollment failed. The next request will retry the same enrollment; it will not switch strategies.");
93
+ }
94
+ });
95
+ pi.on("session_tree", (_event, ctx) => restore(ctx));
96
+ pi.on("session_shutdown", () => { generation++; pending = undefined; thread = undefined; });
97
+ pi.on("before_provider_request", async (event, ctx) => {
98
+ if (!thread) return;
99
+ const requestGeneration = generation;
100
+ try {
101
+ if (!supported || ctx.model?.provider !== PROVIDER_NAME || !isRecord(event.payload)) {
102
+ throw new Error("Classifier thread requires the supported Weave provider");
103
+ }
104
+ await ensureTicket(ctx);
105
+ if (generation !== requestGeneration || !thread?.threadToken || ctx.signal?.aborted) throw new Error("Classifier thread changed");
106
+ return { ...event.payload, [THREAD_FIELD]: thread.threadToken };
107
+ } catch {
108
+ // Pi catches extension exceptions; only abort prevents an unticketed dispatch.
109
+ ctx.abort();
110
+ notify(ctx, "Classifier request stopped: enrollment or session identity is unavailable. No fallback request was sent.");
111
+ }
112
+ });
113
+ pi.on("session_before_compact", (_event, ctx) => {
114
+ if (!thread) return;
115
+ notify(ctx, "Classifier chats require complete history. Compaction is unavailable; start a new chat.");
116
+ return { cancel: true };
117
+ });
118
+ return () => thread !== undefined;
119
+ }
@@ -235,6 +235,7 @@ export const WEAVE_MODELS: ProviderModelConfig[] = [
235
235
  model("claude-sonnet-4-6", "Claude Sonnet 4.6 (via Weave Router)", 64000, 1_000_000),
236
236
  model("claude-haiku-4-5", "Claude Haiku 4.5 (via Weave Router)", 32000, 200_000),
237
237
  model("grok-4.6", "Grok 4.6 (via Weave Router)", 131072, 500_000),
238
+ model("grok-4.7", "Grok 4.7 (via Weave Router)", 131072, 500_000),
238
239
  model("qwen/qwen3.8-max", "Qwen 3.8 Max (via Weave Router)", 131072, 1_000_000),
239
240
  ];
240
241
 
@@ -79,6 +79,7 @@ export function registerEscalationCompaction(
79
79
  pi: ExtensionAPI,
80
80
  request: typeof fetch = fetch,
81
81
  version: string = VERSION,
82
+ classifierThreadActive = () => false,
82
83
  ): () => boolean {
83
84
  const [major, minor] = version.split(".").map(Number);
84
85
  if (major === 0 && minor < 83) {
@@ -142,6 +143,7 @@ export function registerEscalationCompaction(
142
143
  };
143
144
 
144
145
  pi.on("before_provider_request", async (event, ctx) => {
146
+ if (classifierThreadActive()) return;
145
147
  if (process.env.WEAVE_PI_ESCALATION_COMPACTION === "0" || isSubagent() || ctx.model?.provider !== PROVIDER_NAME) return;
146
148
  if (!isRecord(event.payload)) return;
147
149
  let payload = sessionToken ? { ...event.payload, weave_session: sessionToken } : event.payload;
@@ -22,6 +22,7 @@
22
22
  import { fileURLToPath } from "node:url";
23
23
  import type { ExtensionAPI } from "@mariozechner/pi-coding-agent";
24
24
  import { registerBetaCommand } from "./beta.js";
25
+ import { registerClassifierThread } from "./classifier-thread.js";
25
26
  import { isSubagent } from "./config.js";
26
27
  import { registerCompaction } from "./compaction.js";
27
28
  import { registerEscalationCompaction } from "./escalation.js";
@@ -44,13 +45,14 @@ export default function (pi: ExtensionAPI): void {
44
45
  pi.on("session_start", () => registerWeave(pi));
45
46
 
46
47
  registerMetadata(pi);
48
+ const classifierThreadActive = registerClassifierThread(pi);
47
49
  registerBetaCommand(pi);
48
50
  registerForceModelCommands(pi);
49
51
  registerRoutedModel(pi);
50
52
  if (!isSubagent()) registerWooly(pi);
51
53
  let handoffPending = () => false;
52
- registerCompaction(pi, undefined, () => handoffPending());
53
- handoffPending = registerEscalationCompaction(pi);
54
+ registerCompaction(pi, undefined, () => handoffPending() || classifierThreadActive());
55
+ handoffPending = registerEscalationCompaction(pi, undefined, undefined, classifierThreadActive);
54
56
 
55
57
  if (process.env.WEAVE_NO_SAFETY !== "1") registerSafety(pi);
56
58
 
@@ -7,7 +7,7 @@ export interface ModelPricing {
7
7
  cacheReadMultiplier: number;
8
8
  }
9
9
 
10
- export const PRICING_VERSION = "catalog-sha256:a96c21de7b4ad8ef";
10
+ export const PRICING_VERSION = "catalog-sha256:d1898e95669c5daf";
11
11
 
12
12
  export const MODEL_PRICING: Readonly<Record<string, ModelPricing>> = Object.freeze({
13
13
  "claude-fable-5": { inputUsdPerMillion: 10, outputUsdPerMillion: 50, cacheReadMultiplier: 0.1 },
@@ -66,6 +66,7 @@ export const MODEL_PRICING: Readonly<Record<string, ModelPricing>> = Object.free
66
66
  "gpt-6-astra": { inputUsdPerMillion: 10, outputUsdPerMillion: 50, cacheReadMultiplier: 0.1 },
67
67
  "grok-4.5": { inputUsdPerMillion: 2, outputUsdPerMillion: 6, cacheReadMultiplier: 0.25 },
68
68
  "grok-4.6": { inputUsdPerMillion: 2, outputUsdPerMillion: 6, cacheReadMultiplier: 0.25 },
69
+ "grok-4.7": { inputUsdPerMillion: 2, outputUsdPerMillion: 6, cacheReadMultiplier: 0.25 },
69
70
  "minimax/minimax-m2.7": { inputUsdPerMillion: 0.3, outputUsdPerMillion: 1.2, cacheReadMultiplier: 0.2 },
70
71
  "minimax/minimax-m3": { inputUsdPerMillion: 0.3, outputUsdPerMillion: 1.2, cacheReadMultiplier: 0.2 },
71
72
  "mistralai/mistral-small-2603": { inputUsdPerMillion: 0.2, outputUsdPerMillion: 0.6, cacheReadMultiplier: 0.1 },