@weave-os/router 0.2.31 → 0.2.33
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 +28 -1
- package/desktop-shim.js +228 -0
- package/install.sh +464 -9
- package/package.json +2 -1
- package/uninstall.sh +86 -4
- package/windows.js +32 -2
package/cc-statusline.sh
CHANGED
|
@@ -377,6 +377,9 @@ weave_hidden_gate() {
|
|
|
377
377
|
local cache="$cache_dir/display-settings${script_slug}"
|
|
378
378
|
local ttl="${WEAVE_DISPLAY_SETTINGS_TTL_SECONDS:-3600}"
|
|
379
379
|
|
|
380
|
+
# Linked plans that need a fresh login, from the last successful refresh.
|
|
381
|
+
weave_disconnected_plans="$(cat "$cache.plans" 2>/dev/null)"
|
|
382
|
+
|
|
380
383
|
local now mtime fresh="false"
|
|
381
384
|
now="$(date +%s 2>/dev/null)" || now=0
|
|
382
385
|
if [ -f "$cache" ]; then
|
|
@@ -476,6 +479,8 @@ weave_hidden_gate() {
|
|
|
476
479
|
else
|
|
477
480
|
printf '0' >"$tmp" 2>/dev/null && mv "$tmp" "$cache" 2>/dev/null
|
|
478
481
|
fi
|
|
482
|
+
plans="$(printf '%s' "$body" | jq -r '[.disconnected_plans[]? | select(type == "string" and test("^[a-z]+$"))] | join(" ")' 2>/dev/null)"
|
|
483
|
+
printf '%s' "$plans" >"$tmp" 2>/dev/null && mv "$tmp" "$cache.plans" 2>/dev/null
|
|
479
484
|
rm -f "$tmp" 2>/dev/null
|
|
480
485
|
) >/dev/null 2>&1 &
|
|
481
486
|
disown 2>/dev/null || true
|
|
@@ -1085,7 +1090,8 @@ brand=$'\033[38;2;255;108;71mWEAVE ROUTER\033[0m'
|
|
|
1085
1090
|
# saving.
|
|
1086
1091
|
short_model() { printf '%s' "${1#claude-}"; }
|
|
1087
1092
|
picked=""
|
|
1088
|
-
|
|
1093
|
+
# Weave Auto is a routing choice, not a model, so only the served model is shown.
|
|
1094
|
+
if [[ -n "$selected_display" && "$selected_display" != "?" && "$requested_norm" != "weave-auto" ]]; then
|
|
1089
1095
|
picked="$(short_model "$requested_norm")"
|
|
1090
1096
|
fi
|
|
1091
1097
|
status_text=""
|
|
@@ -1116,6 +1122,27 @@ if [[ "$has_pin_record" == "true" ]]; then
|
|
|
1116
1122
|
status_text="$status_text · last pin: $last_pin_model"
|
|
1117
1123
|
fi
|
|
1118
1124
|
|
|
1125
|
+
# Point the reconnect command at this install: a bare login reads the
|
|
1126
|
+
# user-scope config, which a project or --dir install doesn't use.
|
|
1127
|
+
weave_login_scope=""
|
|
1128
|
+
if [ -n "${weave_disconnected_plans:-}" ]; then
|
|
1129
|
+
weave_sl_dir="$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" 2>/dev/null && pwd)"
|
|
1130
|
+
case "$weave_sl_dir" in
|
|
1131
|
+
*/.claude)
|
|
1132
|
+
weave_login_scope=" --dir $(printf '%q' "${weave_sl_dir%/.claude}")"
|
|
1133
|
+
if grep -q 'X-Weave-Router-Key' "$weave_sl_dir/settings.local.json" 2>/dev/null; then
|
|
1134
|
+
weave_login_scope=" --scope project$weave_login_scope"
|
|
1135
|
+
fi
|
|
1136
|
+
;;
|
|
1137
|
+
esac
|
|
1138
|
+
fi
|
|
1139
|
+
for weave_plan in ${weave_disconnected_plans:-}; do
|
|
1140
|
+
case "$weave_plan" in
|
|
1141
|
+
claude) status_text="$status_text · Claude plan disconnected: run npx @weave-os/router login claude$weave_login_scope" ;;
|
|
1142
|
+
codex) status_text="$status_text · Codex plan disconnected: run npx @weave-os/router login codex$weave_login_scope" ;;
|
|
1143
|
+
esac
|
|
1144
|
+
done
|
|
1145
|
+
|
|
1119
1146
|
# /router-status reads this back through the prompt hook, so it can answer
|
|
1120
1147
|
# without a model turn.
|
|
1121
1148
|
weave_cache_status_line() {
|
package/desktop-shim.js
ADDED
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Local HTTPS proxy for Claude Desktop's Code tab and Cowork. Desktop forces
|
|
3
|
+
// ANTHROPIC_BASE_URL to Anthropic, but gives both the OS proxy (here, the PAC
|
|
4
|
+
// file served at /proxy.pac) and the OS certificate store. This proxy terminates
|
|
5
|
+
// TLS for api.anthropic.com only and sends Desktop's Messages API calls to the
|
|
6
|
+
// Weave Router with the router key added. Everything else, including other apps'
|
|
7
|
+
// api.anthropic.com traffic and every other host, passes through untouched.
|
|
8
|
+
|
|
9
|
+
"use strict";
|
|
10
|
+
|
|
11
|
+
const { execFile } = require("node:child_process");
|
|
12
|
+
const fs = require("node:fs");
|
|
13
|
+
const http = require("node:http");
|
|
14
|
+
const https = require("node:https");
|
|
15
|
+
const net = require("node:net");
|
|
16
|
+
const tls = require("node:tls");
|
|
17
|
+
|
|
18
|
+
const INTERCEPT_HOST = "api.anthropic.com";
|
|
19
|
+
const ROUTER_KEY_HEADER = "x-weave-router-key";
|
|
20
|
+
// Claude Code's user agent names its entrypoint: "claude-desktop" for the Code
|
|
21
|
+
// tab, "local-agent" for Cowork.
|
|
22
|
+
const DESKTOP_USER_AGENT = /[(,]\s*(claude-desktop|local-agent)(?![\w-])/;
|
|
23
|
+
const HOP_BY_HOP = new Set([
|
|
24
|
+
"connection",
|
|
25
|
+
"keep-alive",
|
|
26
|
+
"proxy-authenticate",
|
|
27
|
+
"proxy-authorization",
|
|
28
|
+
"proxy-connection",
|
|
29
|
+
"te",
|
|
30
|
+
"trailer",
|
|
31
|
+
"transfer-encoding",
|
|
32
|
+
"upgrade",
|
|
33
|
+
]);
|
|
34
|
+
|
|
35
|
+
function loadConfig(file) {
|
|
36
|
+
const parsed = JSON.parse(fs.readFileSync(file, "utf8"));
|
|
37
|
+
for (const field of ["router_base_url", "cert_file", "key_file"]) {
|
|
38
|
+
if (typeof parsed[field] !== "string" || parsed[field] === "") {
|
|
39
|
+
throw new Error(`${file}: missing ${field}`);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return {
|
|
43
|
+
host: parsed.listen_host || "127.0.0.1",
|
|
44
|
+
port: Number(parsed.listen_port ?? 47821),
|
|
45
|
+
router: new URL(parsed.router_base_url),
|
|
46
|
+
routerKey: typeof parsed.router_key === "string" ? parsed.router_key : "",
|
|
47
|
+
anthropic: new URL(parsed.anthropic_origin || `https://${INTERCEPT_HOST}`),
|
|
48
|
+
cert: fs.readFileSync(parsed.cert_file),
|
|
49
|
+
key: fs.readFileSync(parsed.key_file),
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function routesToRouter(req) {
|
|
54
|
+
const path = req.url;
|
|
55
|
+
const isMessages = path === "/v1/messages" || path.startsWith("/v1/messages/") || path.startsWith("/v1/messages?");
|
|
56
|
+
return isMessages && DESKTOP_USER_AGENT.test(req.headers["user-agent"] || "");
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Loopback is shared by every OS account and the proxy adds the installing
|
|
60
|
+
// user's router key, so it only serves that user's processes. peerUid finds
|
|
61
|
+
// the OS user owning the client end of a loopback connection.
|
|
62
|
+
function peerUid(socket, callback) {
|
|
63
|
+
// Match the whole 4-tuple: another user can reuse the owner's source port
|
|
64
|
+
// from a different loopback address such as 127.0.0.2.
|
|
65
|
+
if (process.platform === "linux") {
|
|
66
|
+
// /proc/net/tcp writes IPv4 endpoints as little-endian hex, e.g. 0100007F:B8CD.
|
|
67
|
+
const procEndpoint = (address, port) => {
|
|
68
|
+
const octets = address.replace(/^::ffff:/, "").split(".").reverse();
|
|
69
|
+
const ip = octets.map((octet) => Number(octet).toString(16).padStart(2, "0")).join("");
|
|
70
|
+
return `${ip}:${port.toString(16).padStart(4, "0")}`.toUpperCase();
|
|
71
|
+
};
|
|
72
|
+
const client = procEndpoint(socket.remoteAddress, socket.remotePort);
|
|
73
|
+
const proxy = procEndpoint(socket.localAddress, socket.localPort);
|
|
74
|
+
for (const row of fs.readFileSync("/proc/net/tcp", "utf8").split("\n").slice(1)) {
|
|
75
|
+
const [, local, remote, , , , , uid] = row.trim().split(/\s+/);
|
|
76
|
+
if (local === client && remote === proxy) return callback(Number(uid));
|
|
77
|
+
}
|
|
78
|
+
return callback(null);
|
|
79
|
+
}
|
|
80
|
+
// lsof without root lists only the caller's own processes, so another
|
|
81
|
+
// user's client is simply not found.
|
|
82
|
+
const connection = `n${socket.remoteAddress}:${socket.remotePort}->${socket.localAddress}:${socket.localPort}`;
|
|
83
|
+
execFile("lsof", ["-nP", "-a", `-iTCP:${socket.remotePort}`, "-sTCP:ESTABLISHED", "-Fun"], (_err, out = "") => {
|
|
84
|
+
let uid = null;
|
|
85
|
+
for (const line of out.split("\n")) {
|
|
86
|
+
if (line.startsWith("u")) uid = Number(line.slice(1));
|
|
87
|
+
if (line === connection) return callback(uid);
|
|
88
|
+
}
|
|
89
|
+
callback(null);
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function pacFile(port) {
|
|
94
|
+
return `function FindProxyForURL(url, host) {
|
|
95
|
+
if (host === "${INTERCEPT_HOST}") return "PROXY 127.0.0.1:${port}";
|
|
96
|
+
return "DIRECT";
|
|
97
|
+
}
|
|
98
|
+
`;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function forward(cfg, req, res) {
|
|
102
|
+
const toRouter = routesToRouter(req);
|
|
103
|
+
const target = toRouter ? cfg.router : cfg.anthropic;
|
|
104
|
+
const headers = {};
|
|
105
|
+
for (const [name, value] of Object.entries(req.headers)) {
|
|
106
|
+
if (!HOP_BY_HOP.has(name) && name !== ROUTER_KEY_HEADER) headers[name] = value;
|
|
107
|
+
}
|
|
108
|
+
headers.host = target.host;
|
|
109
|
+
if (toRouter && cfg.routerKey) headers[ROUTER_KEY_HEADER] = cfg.routerKey;
|
|
110
|
+
|
|
111
|
+
const client = target.protocol === "http:" ? http : https;
|
|
112
|
+
const upstream = client.request(
|
|
113
|
+
{
|
|
114
|
+
protocol: target.protocol,
|
|
115
|
+
hostname: target.hostname,
|
|
116
|
+
port: target.port || (target.protocol === "http:" ? 80 : 443),
|
|
117
|
+
method: req.method,
|
|
118
|
+
path: target.pathname.replace(/\/+$/, "") + req.url,
|
|
119
|
+
headers,
|
|
120
|
+
},
|
|
121
|
+
(upstreamRes) => {
|
|
122
|
+
const out = {};
|
|
123
|
+
for (const [name, value] of Object.entries(upstreamRes.headers)) {
|
|
124
|
+
if (!HOP_BY_HOP.has(name)) out[name] = value;
|
|
125
|
+
}
|
|
126
|
+
res.writeHead(upstreamRes.statusCode, out);
|
|
127
|
+
res.flushHeaders();
|
|
128
|
+
// A body cut off mid-stream must reach Desktop as a broken response, not
|
|
129
|
+
// a connection that silently stays open.
|
|
130
|
+
upstreamRes.on("close", () => {
|
|
131
|
+
if (!upstreamRes.complete) res.destroy();
|
|
132
|
+
});
|
|
133
|
+
upstreamRes.pipe(res);
|
|
134
|
+
},
|
|
135
|
+
);
|
|
136
|
+
upstream.setNoDelay(true);
|
|
137
|
+
upstream.on("error", (err) => {
|
|
138
|
+
if (res.destroyed) return;
|
|
139
|
+
console.error(`${req.method} ${req.url} -> ${target.host}: ${err.message}`);
|
|
140
|
+
if (!res.headersSent) {
|
|
141
|
+
res.writeHead(502, { "content-type": "application/json" });
|
|
142
|
+
res.end(JSON.stringify({
|
|
143
|
+
type: "error",
|
|
144
|
+
error: { type: "api_error", message: `Weave Router desktop proxy could not reach ${target.host}: ${err.message}` },
|
|
145
|
+
}));
|
|
146
|
+
} else {
|
|
147
|
+
res.destroy(err);
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
// Desktop's Stop closes the response; stop the upstream generation with it.
|
|
151
|
+
res.on("close", () => {
|
|
152
|
+
if (!res.writableFinished) upstream.destroy();
|
|
153
|
+
});
|
|
154
|
+
req.pipe(upstream);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function start(cfg) {
|
|
158
|
+
const intercepted = http.createServer((req, res) => forward(cfg, req, res));
|
|
159
|
+
const secureContext = tls.createSecureContext({ cert: cfg.cert, key: cfg.key });
|
|
160
|
+
|
|
161
|
+
const proxy = http.createServer((req, res) => {
|
|
162
|
+
if (req.method === "GET" && req.url === "/proxy.pac") {
|
|
163
|
+
res.writeHead(200, { "content-type": "application/x-ns-proxy-autoconfig" });
|
|
164
|
+
res.end(pacFile(proxy.address().port));
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
if (req.method === "GET" && req.url === "/health") {
|
|
168
|
+
res.writeHead(200, { "content-type": "text/plain" });
|
|
169
|
+
res.end("ok\n");
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
res.writeHead(405, { "content-type": "text/plain" });
|
|
173
|
+
res.end("CONNECT only\n");
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
proxy.on("connect", (req, socket, head) => {
|
|
177
|
+
socket.on("error", () => socket.destroy());
|
|
178
|
+
peerUid(socket, (uid) => {
|
|
179
|
+
if (uid === process.getuid()) tunnel(req, socket, head);
|
|
180
|
+
else socket.end("HTTP/1.1 403 Forbidden\r\nContent-Length: 0\r\n\r\n");
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
function tunnel(req, socket, head) {
|
|
185
|
+
let target;
|
|
186
|
+
try {
|
|
187
|
+
target = new URL(`http://${req.url}`);
|
|
188
|
+
} catch {
|
|
189
|
+
socket.end("HTTP/1.1 400 Bad Request\r\nContent-Length: 0\r\n\r\n");
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
const host = target.hostname.replace(/^\[|\]$/g, "");
|
|
193
|
+
if (host === INTERCEPT_HOST) {
|
|
194
|
+
socket.write("HTTP/1.1 200 Connection Established\r\n\r\n");
|
|
195
|
+
if (head.length) socket.unshift(head);
|
|
196
|
+
const tlsSocket = new tls.TLSSocket(socket, { isServer: true, secureContext, ALPNProtocols: ["http/1.1"] });
|
|
197
|
+
tlsSocket.on("error", () => tlsSocket.destroy());
|
|
198
|
+
intercepted.emit("connection", tlsSocket);
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
const upstream = net.connect(Number(target.port) || 443, host, () => {
|
|
202
|
+
socket.write("HTTP/1.1 200 Connection Established\r\n\r\n");
|
|
203
|
+
if (head.length) upstream.write(head);
|
|
204
|
+
upstream.pipe(socket);
|
|
205
|
+
socket.pipe(upstream);
|
|
206
|
+
});
|
|
207
|
+
upstream.on("error", () => {
|
|
208
|
+
socket.end("HTTP/1.1 502 Bad Gateway\r\n\r\n");
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
proxy.listen(cfg.port, cfg.host, () => {
|
|
213
|
+
const address = proxy.address();
|
|
214
|
+
console.log(`Weave Router desktop proxy listening on ${address.address}:${address.port}, router ${cfg.router.origin}`);
|
|
215
|
+
});
|
|
216
|
+
return proxy;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
module.exports = { loadConfig, peerUid, routesToRouter, start };
|
|
220
|
+
|
|
221
|
+
if (require.main === module) {
|
|
222
|
+
const file = process.argv[2];
|
|
223
|
+
if (!file) {
|
|
224
|
+
console.error("usage: desktop-shim.js <config.json>");
|
|
225
|
+
process.exit(2);
|
|
226
|
+
}
|
|
227
|
+
start(loadConfig(file));
|
|
228
|
+
}
|
package/install.sh
CHANGED
|
@@ -233,6 +233,7 @@ uninstall_cmd() {
|
|
|
233
233
|
opencode) cmd="$cmd --opencode" ;;
|
|
234
234
|
pi) cmd="$cmd --pi" ;;
|
|
235
235
|
copilot) cmd="$cmd --copilot" ;;
|
|
236
|
+
claude-desktop) cmd="$cmd --claude-desktop" ;;
|
|
236
237
|
esac
|
|
237
238
|
[ "$scope" = "project" ] && cmd="$cmd --scope project"
|
|
238
239
|
[ -n "$install_dir" ] && cmd="$cmd --dir $(printf '%q' "$install_dir")"
|
|
@@ -279,6 +280,7 @@ print_banner() {
|
|
|
279
280
|
opencode) target_label="opencode installer" ;;
|
|
280
281
|
pi) target_label="pi installer" ;;
|
|
281
282
|
copilot) target_label="GitHub Copilot CLI installer" ;;
|
|
283
|
+
claude-desktop) target_label="Claude Desktop installer" ;;
|
|
282
284
|
*) target_label="Claude Code installer" ;;
|
|
283
285
|
esac
|
|
284
286
|
printf '\n'
|
|
@@ -401,6 +403,7 @@ Set up
|
|
|
401
403
|
$npx setup --claude --codex install for both (one key prompt)
|
|
402
404
|
$npx --opencode | --pi install for opencode or pi
|
|
403
405
|
$npx --copilot add Weave Router to Copilot CLI's /model picker
|
|
406
|
+
$npx --claude-desktop route Claude Desktop's Code tab and Cowork (local proxy)
|
|
404
407
|
|
|
405
408
|
Every day
|
|
406
409
|
$npx status is each tool routed, signed in, working?
|
|
@@ -931,7 +934,7 @@ write_codex_config() {
|
|
|
931
934
|
# Tag the client so telemetry can attribute traffic to Codex vs other CLIs
|
|
932
935
|
# that share the same router key. The router otherwise has to guess from
|
|
933
936
|
# User-Agent.
|
|
934
|
-
headers_parts="${headers_parts}, \"X-App\" = \"codex\", \"X-Weave-Codex-Native-Model-Pin\" = \"1\""
|
|
937
|
+
headers_parts="${headers_parts}, \"X-App\" = \"codex\", \"X-Weave-Codex-Native-Model-Pin\" = \"1\", \"X-Weave-Codex-Model-Catalog\" = \"1\""
|
|
935
938
|
# No strategy header: pinning one here freezes installed clients on whatever
|
|
936
939
|
# policy was current at install time, so a deployment-default change never
|
|
937
940
|
# reaches them. Every endpoint, hosted or self-hosted, uses its own default.
|
|
@@ -1038,6 +1041,7 @@ name = "Weave Router"
|
|
|
1038
1041
|
base_url = "${esc_url}/v1"
|
|
1039
1042
|
wire_api = "responses"
|
|
1040
1043
|
requires_openai_auth = true
|
|
1044
|
+
model_catalog_url = "${esc_url}/v1/codex/models"
|
|
1041
1045
|
${headers_line}
|
|
1042
1046
|
${hook_block}
|
|
1043
1047
|
${WEAVE_CODEX_END_MARKER}
|
|
@@ -1780,6 +1784,9 @@ while [ $# -gt 0 ]; do
|
|
|
1780
1784
|
lsp_langs="${2:-}"; shift 2
|
|
1781
1785
|
[ -n "$lsp_langs" ] || { err "--lsp requires a comma-separated language list (go,typescript,python,rust)."; exit 2; }
|
|
1782
1786
|
;;
|
|
1787
|
+
--claude-desktop)
|
|
1788
|
+
target="claude-desktop"; target_explicit="true"; shift
|
|
1789
|
+
;;
|
|
1783
1790
|
--claude)
|
|
1784
1791
|
# No-op selector for symmetry with --codex / --opencode. Useful in
|
|
1785
1792
|
# pipelines that want to skip the interactive picker without depending
|
|
@@ -2018,6 +2025,16 @@ if [ "$target" = "copilot" ] && [ "$scope" = "project" ]; then
|
|
|
2018
2025
|
err "--copilot installs in user scope only (Copilot CLI has no project-level providers.json). Drop --scope project, or use --dir for a throwaway COPILOT_HOME."
|
|
2019
2026
|
exit 2
|
|
2020
2027
|
fi
|
|
2028
|
+
# Claude Desktop is configured through a local proxy service, not a settings
|
|
2029
|
+
# file, so there is nothing to toggle or scope per repo.
|
|
2030
|
+
if [ "$target" = "claude-desktop" ] && [ "$mode" != "install" ] && [ "$mode" != "update" ]; then
|
|
2031
|
+
err "Toggle verbs (off/on/status) aren't supported for --claude-desktop. Run 'npx $npm_package_name --uninstall --claude-desktop' to go direct."
|
|
2032
|
+
exit 2
|
|
2033
|
+
fi
|
|
2034
|
+
if [ "$target" = "claude-desktop" ] && [ "$scope" = "project" ]; then
|
|
2035
|
+
err "--claude-desktop installs in user scope only. Drop --scope project."
|
|
2036
|
+
exit 2
|
|
2037
|
+
fi
|
|
2021
2038
|
|
|
2022
2039
|
if [ -z "$base_url" ]; then
|
|
2023
2040
|
base_url="$DEFAULT_BASE_URL"
|
|
@@ -2071,7 +2088,7 @@ fi
|
|
|
2071
2088
|
# they keep the user-scope default unless the caller explicitly selects a
|
|
2072
2089
|
# project scope. Non-interactive installs (CI, `curl | sh --non-interactive`)
|
|
2073
2090
|
# silently use the "user" default.
|
|
2074
|
-
if [ "$mode" = "install" ] && [ -z "$install_dir" ] && [ "$scope_explicit" = "false" ] && [ "$non_interactive" = "false" ] && [ "$target" != "copilot" ] && [ -r /dev/tty ]; then
|
|
2091
|
+
if [ "$mode" = "install" ] && [ -z "$install_dir" ] && [ "$scope_explicit" = "false" ] && [ "$non_interactive" = "false" ] && [ "$target" != "copilot" ] && [ "$target" != "claude-desktop" ] && [ -r /dev/tty ]; then
|
|
2075
2092
|
# Per-target paths so the prompt text matches what actually gets written.
|
|
2076
2093
|
case "$target" in
|
|
2077
2094
|
codex)
|
|
@@ -2162,7 +2179,7 @@ fi
|
|
|
2162
2179
|
# payloads with jq regardless of which client's config supplied the endpoint,
|
|
2163
2180
|
# so require it there too rather than dying mid-render on `jq: command not
|
|
2164
2181
|
# found`. Installing Codex itself still needs no jq.
|
|
2165
|
-
if [ "$target" = "claude" ] || [ "$target" = "opencode" ] || [ "$target" = "pi" ] || [ "$target" = "copilot" ] \
|
|
2182
|
+
if [ "$target" = "claude" ] || [ "$target" = "opencode" ] || [ "$target" = "pi" ] || [ "$target" = "copilot" ] || [ "$target" = "claude-desktop" ] \
|
|
2166
2183
|
|| { [ "$mode" = "models" ] && [ "$target" = "codex" ]; }; then
|
|
2167
2184
|
ensure_jq
|
|
2168
2185
|
fi
|
|
@@ -2205,6 +2222,10 @@ case "$target" in
|
|
|
2205
2222
|
warn "Continuing — models.json/settings.json will be written and take effect once pi is installed."
|
|
2206
2223
|
fi
|
|
2207
2224
|
;;
|
|
2225
|
+
claude-desktop)
|
|
2226
|
+
require_cmd node "the proxy runs on Node.js 18+: https://nodejs.org"
|
|
2227
|
+
require_cmd openssl "macOS: preinstalled; Linux: install openssl from your package manager"
|
|
2228
|
+
;;
|
|
2208
2229
|
copilot)
|
|
2209
2230
|
if ! command -v copilot >/dev/null 2>&1; then
|
|
2210
2231
|
warn "'copilot' not found on PATH. Install with 'npm install -g @github/copilot', then re-run this script."
|
|
@@ -2439,6 +2460,11 @@ if [ "$target" = "claude" ]; then
|
|
|
2439
2460
|
if [ "$statusline_install" = "true" ]; then
|
|
2440
2461
|
mkdir -p "$statusline_dir"
|
|
2441
2462
|
fi
|
|
2463
|
+
elif [ "$target" = "claude-desktop" ]; then
|
|
2464
|
+
desktop_shim_dir="$settings_base/.weave-router/desktop-shim"
|
|
2465
|
+
desktop_shim_config="$desktop_shim_dir/config.json"
|
|
2466
|
+
mkdir -p "$desktop_shim_dir"
|
|
2467
|
+
chmod 700 "$desktop_shim_dir"
|
|
2442
2468
|
elif [ "$target" = "codex" ]; then
|
|
2443
2469
|
# Codex CLI reads config from ~/.codex/config.toml by default. For project
|
|
2444
2470
|
# scope we write to <repo>/.codex/config.toml; the user invokes Codex with
|
|
@@ -2743,6 +2769,7 @@ read_installed_key() {
|
|
|
2743
2769
|
opencode) read_opencode_key "$opencode_config_file" ;;
|
|
2744
2770
|
pi) read_pi_key ;;
|
|
2745
2771
|
copilot) read_copilot_key ;;
|
|
2772
|
+
claude-desktop) json_get "$desktop_shim_config" '.router_key' ;;
|
|
2746
2773
|
esac
|
|
2747
2774
|
}
|
|
2748
2775
|
|
|
@@ -2823,6 +2850,10 @@ resolve_installed_endpoint() {
|
|
|
2823
2850
|
resolve_installed_base_url
|
|
2824
2851
|
return 0
|
|
2825
2852
|
;;
|
|
2853
|
+
claude-desktop)
|
|
2854
|
+
json_get "$desktop_shim_config" '.router_base_url'
|
|
2855
|
+
return 0
|
|
2856
|
+
;;
|
|
2826
2857
|
codex)
|
|
2827
2858
|
# Read base_url from the [model_providers.weave] table wherever it sits,
|
|
2828
2859
|
# not only from between the managed markers. Codex drops our comment
|
|
@@ -2980,6 +3011,59 @@ gitignore_add() {
|
|
|
2980
3011
|
fi
|
|
2981
3012
|
}
|
|
2982
3013
|
|
|
3014
|
+
# Claude Code sends a picker model ID verbatim (minus [1m], which it turns into
|
|
3015
|
+
# the 1M-context beta); the router routes only weave-auto and serves every other
|
|
3016
|
+
# model as-is (X-Weave-Model-Passthrough).
|
|
3017
|
+
CLAUDE_WEAVE_AUTO_OPTION='{"model":"weave-auto[1m]","label":"Weave Auto","description":"Weave picks the best model for each turn","behavesAs":"claude-opus-5-5"}'
|
|
3018
|
+
# shellcheck disable=SC2016 # jq variables, expanded by jq.
|
|
3019
|
+
CLAUDE_WEAVE_AUTO_ADD_JQ='.modelPicker = ((.modelPicker // {}) | .options = ([$option] + ((.options // []) | map(select(.model != "weave-auto" and .model != "weave-auto[1m]")))))
|
|
3020
|
+
| (if $set_model == "force" then .model = $option.model | (if (.env | type) == "object" then .env |= del(.ANTHROPIC_MODEL) else . end)
|
|
3021
|
+
elif ($set_model == "true" and (has("model") | not)) or .model == "weave-auto" then .model = $option.model else . end)'
|
|
3022
|
+
CLAUDE_WEAVE_AUTO_STRIP_JQ='(if (.model == "weave-auto" or .model == "weave-auto[1m]") then del(.model) else . end)
|
|
3023
|
+
| (if (.modelPicker | type) == "object" then
|
|
3024
|
+
.modelPicker.options = ((.modelPicker.options // []) | map(select(.model != "weave-auto" and .model != "weave-auto[1m]")))
|
|
3025
|
+
| (if (.modelPicker.options | length) == 0 then del(.modelPicker.options) else . end)
|
|
3026
|
+
| (if (.modelPicker | length) == 0 then del(.modelPicker) else . end)
|
|
3027
|
+
else . end)'
|
|
3028
|
+
|
|
3029
|
+
# claude_model_unset reports whether no Claude Code settings layer or
|
|
3030
|
+
# ANTHROPIC_MODEL selects a model, so defaulting to Weave Auto overrides nothing.
|
|
3031
|
+
claude_model_unset() {
|
|
3032
|
+
local source
|
|
3033
|
+
[ -z "${ANTHROPIC_MODEL:-}" ] || return 1
|
|
3034
|
+
for source in "$@"; do
|
|
3035
|
+
[ -f "$source" ] || continue
|
|
3036
|
+
if jq -e 'has("model") or (.env.ANTHROPIC_MODEL // "" | length > 0)' "$source" >/dev/null 2>&1; then
|
|
3037
|
+
return 1
|
|
3038
|
+
fi
|
|
3039
|
+
done
|
|
3040
|
+
return 0
|
|
3041
|
+
}
|
|
3042
|
+
|
|
3043
|
+
# claude_passthrough_installed reports whether a settings file already carries
|
|
3044
|
+
# the passthrough header, i.e. this install has been through the Weave Auto rollout.
|
|
3045
|
+
claude_passthrough_installed() {
|
|
3046
|
+
local source
|
|
3047
|
+
for source in "$@"; do
|
|
3048
|
+
[ -f "$source" ] || continue
|
|
3049
|
+
if jq -e '(.env.ANTHROPIC_CUSTOM_HEADERS // "") | test("(^|\\n)X-Weave-Model-Passthrough:")' "$source" >/dev/null 2>&1; then
|
|
3050
|
+
return 0
|
|
3051
|
+
fi
|
|
3052
|
+
done
|
|
3053
|
+
return 1
|
|
3054
|
+
}
|
|
3055
|
+
|
|
3056
|
+
# apply_claude_weave_auto creates $1 when missing and keeps a non-shared
|
|
3057
|
+
# settings file private (mode 600). $2 is "force" (select Weave Auto over any
|
|
3058
|
+
# saved model), "true" (select it only when no model is set) or "false".
|
|
3059
|
+
apply_claude_weave_auto() {
|
|
3060
|
+
local target="$1" set_model="$2" merged
|
|
3061
|
+
[ -f "$target" ] || printf '{}\n' >"$target"
|
|
3062
|
+
merged="$(jq --argjson option "$CLAUDE_WEAVE_AUTO_OPTION" --arg set_model "$set_model" "$CLAUDE_WEAVE_AUTO_ADD_JQ" "$target")"
|
|
3063
|
+
printf '%s\n' "$merged" >"$target"
|
|
3064
|
+
[ "$target" = "$settings_file" ] || chmod 600 "$target"
|
|
3065
|
+
}
|
|
3066
|
+
|
|
2983
3067
|
prepare_claude_context_window() {
|
|
2984
3068
|
context_settings_file="$settings_file"
|
|
2985
3069
|
if [ "$scope" = "project" ] && [ -z "$install_dir" ]; then
|
|
@@ -3112,22 +3196,33 @@ toggle_claude() {
|
|
|
3112
3196
|
# base URL to Anthropic in the local file only — committed settings.json
|
|
3113
3197
|
# is never touched, so this stays out of `git diff`.
|
|
3114
3198
|
if [ -f "$local_settings_file" ]; then
|
|
3115
|
-
jq '{env: (.env // {})}' "$local_settings_file" >"$parked"
|
|
3116
|
-
merged="$(jq '.env = ((.env // {} | del(.ANTHROPIC_CUSTOM_HEADERS)) + {ANTHROPIC_BASE_URL: "https://api.anthropic.com"})' "$local_settings_file")"
|
|
3199
|
+
jq '{env: (.env // {}), weave_auto_selected: (.model == "weave-auto" or .model == "weave-auto[1m]")}' "$local_settings_file" >"$parked"
|
|
3200
|
+
merged="$(jq '.env = ((.env // {} | del(.ANTHROPIC_CUSTOM_HEADERS)) + {ANTHROPIC_BASE_URL: "https://api.anthropic.com"}) | '"$CLAUDE_WEAVE_AUTO_STRIP_JQ" "$local_settings_file")"
|
|
3117
3201
|
else
|
|
3118
3202
|
printf '{"env":{}}\n' >"$parked"
|
|
3119
3203
|
merged='{"env":{"ANTHROPIC_BASE_URL":"https://api.anthropic.com"}}'
|
|
3120
3204
|
fi
|
|
3121
3205
|
printf '%s\n' "$merged" >"$local_settings_file"
|
|
3206
|
+
# A Weave Auto default inherited from user scope would reach Anthropic
|
|
3207
|
+
# directly, so pin a real model locally while off.
|
|
3208
|
+
local inherited_model
|
|
3209
|
+
inherited_model="$(json_get "$settings_file" '.model')"
|
|
3210
|
+
[ -n "$inherited_model" ] || inherited_model="$(json_get "$HOME/.claude/settings.json" '.model')"
|
|
3211
|
+
if [ -z "$(json_get "$local_settings_file" '.model')" ] && { [ "$inherited_model" = "weave-auto" ] || [ "$inherited_model" = "weave-auto[1m]" ]; }; then
|
|
3212
|
+
merged="$(jq '.model = "opus"' "$local_settings_file")"
|
|
3213
|
+
printf '%s\n' "$merged" >"$local_settings_file"
|
|
3214
|
+
merged="$(jq '.off_pin = "opus"' "$parked")"
|
|
3215
|
+
printf '%s\n' "$merged" >"$parked"
|
|
3216
|
+
fi
|
|
3122
3217
|
chmod 600 "$local_settings_file" "$parked"
|
|
3123
3218
|
gitignore_add ".claude/.weave-parked.json"
|
|
3124
3219
|
else
|
|
3125
3220
|
# Park just the router-owned env keys, then strip them so Claude Code
|
|
3126
3221
|
# falls back to its own Anthropic login.
|
|
3127
|
-
jq '{env: ((.env // {}) | {ANTHROPIC_BASE_URL, ANTHROPIC_CUSTOM_HEADERS, ENABLE_TOOL_SEARCH} | with_entries(select(.value != null)))}' "$settings_file" >"$parked"
|
|
3222
|
+
jq '{env: ((.env // {}) | {ANTHROPIC_BASE_URL, ANTHROPIC_CUSTOM_HEADERS, ENABLE_TOOL_SEARCH} | with_entries(select(.value != null))), weave_auto_selected: (.model == "weave-auto" or .model == "weave-auto[1m]")}' "$settings_file" >"$parked"
|
|
3128
3223
|
chmod 600 "$parked"
|
|
3129
3224
|
merged="$(jq '(.env // {}) |= del(.ANTHROPIC_BASE_URL, .ANTHROPIC_CUSTOM_HEADERS, .ENABLE_TOOL_SEARCH)
|
|
3130
|
-
| (if (.env // {} | length) == 0 then del(.env) else . end)' "$settings_file")"
|
|
3225
|
+
| (if (.env // {} | length) == 0 then del(.env) else . end) | '"$CLAUDE_WEAVE_AUTO_STRIP_JQ" "$settings_file")"
|
|
3131
3226
|
printf '%s\n' "$merged" >"$settings_file"
|
|
3132
3227
|
fi
|
|
3133
3228
|
ok "Claude Code is ${C_BOLD}off${C_RESET} (direct to Anthropic). Restart Claude Code for it to take effect."
|
|
@@ -3194,6 +3289,17 @@ toggle_claude() {
|
|
|
3194
3289
|
merged="$(jq --argjson p "$parked_env" '.env = (((.env // {}) | del(.ANTHROPIC_BASE_URL)) + $p)' "$active")"
|
|
3195
3290
|
printf '%s\n' "$merged" >"$active"
|
|
3196
3291
|
[ "$proj" = "true" ] && chmod 600 "$active"
|
|
3292
|
+
local off_pin
|
|
3293
|
+
off_pin="$(jq -r '.off_pin // empty' "$parked")"
|
|
3294
|
+
if [ -n "$off_pin" ] && [ "$(json_get "$active" '.model')" = "$off_pin" ]; then
|
|
3295
|
+
merged="$(jq 'del(.model)' "$active")"
|
|
3296
|
+
printf '%s\n' "$merged" >"$active"
|
|
3297
|
+
fi
|
|
3298
|
+
if [ "$(jq -r '.weave_auto_selected // false' "$parked")" = "true" ]; then
|
|
3299
|
+
apply_claude_weave_auto "$active" true
|
|
3300
|
+
else
|
|
3301
|
+
apply_claude_weave_auto "$active" false
|
|
3302
|
+
fi
|
|
3197
3303
|
apply_claude_context_window on "$active"
|
|
3198
3304
|
rm -f "$parked"
|
|
3199
3305
|
ok "Claude Code is ${C_BOLD}on${C_RESET} (routing through the Weave Router). Restart Claude Code for it to take effect."
|
|
@@ -4515,6 +4621,22 @@ if [ "$mode" = "update" ] && [ "$base_url_explicit" != "true" ]; then
|
|
|
4515
4621
|
fi
|
|
4516
4622
|
fi
|
|
4517
4623
|
|
|
4624
|
+
# Claude Desktop re-installs keep the proxy's endpoint, and a first install
|
|
4625
|
+
# takes the endpoint and key from the Claude Code CLI install (or the copy
|
|
4626
|
+
# `off --claude` parked): a key is only admitted on its own serving fleet, so
|
|
4627
|
+
# the hosted default can reject it.
|
|
4628
|
+
desktop_cli_key=""
|
|
4629
|
+
if [ "$target" = "claude-desktop" ] && [ "$base_url_explicit" != "true" ] && [ -z "${WEAVE_ROUTER_URL:-}" ]; then
|
|
4630
|
+
installed_base="$(resolve_installed_endpoint)"
|
|
4631
|
+
for cli_settings_file in "$settings_base/.claude/settings.json" "$settings_base/.claude/.weave-parked.json"; do
|
|
4632
|
+
[ -z "$installed_base" ] || break
|
|
4633
|
+
router_shaped_url "$(json_get "$cli_settings_file" '.env.ANTHROPIC_BASE_URL')" || continue
|
|
4634
|
+
installed_base="$(json_get "$cli_settings_file" '.env.ANTHROPIC_BASE_URL')"
|
|
4635
|
+
desktop_cli_key="$(read_claude_key "$cli_settings_file")"
|
|
4636
|
+
done
|
|
4637
|
+
[ -z "$installed_base" ] || base_url="$(strip_trailing_slashes "$installed_base")"
|
|
4638
|
+
fi
|
|
4639
|
+
|
|
4518
4640
|
if [ "$mode" = "install" ]; then
|
|
4519
4641
|
[ "$quiet" = "true" ] || info "scope=${C_BOLD}${scope}${C_RESET} target=${C_BOLD}${target}${C_RESET} base_url=${C_BOLD}${base_url}${C_RESET}"
|
|
4520
4642
|
else
|
|
@@ -4552,6 +4674,7 @@ prompt_for_key() {
|
|
|
4552
4674
|
api_key=""
|
|
4553
4675
|
installed_key=""
|
|
4554
4676
|
[ "$rotate_key" = "true" ] || installed_key="$(read_installed_key)"
|
|
4677
|
+
[ -n "$installed_key" ] || [ "$rotate_key" = "true" ] || installed_key="$desktop_cli_key"
|
|
4555
4678
|
|
|
4556
4679
|
if [ -n "${WEAVE_ROUTER_KEY:-}" ]; then
|
|
4557
4680
|
api_key="$WEAVE_ROUTER_KEY"
|
|
@@ -4954,6 +5077,10 @@ rewrite_installed_key() {
|
|
|
4954
5077
|
chmod 600 "$pi_key_file"
|
|
4955
5078
|
;;
|
|
4956
5079
|
copilot) write_copilot_providers "$copilot_providers_file" "$base_url" "$key" "$user_email" "$user_name" ;;
|
|
5080
|
+
claude-desktop)
|
|
5081
|
+
write_desktop_shim_config "$key"
|
|
5082
|
+
start_desktop_shim_service
|
|
5083
|
+
;;
|
|
4957
5084
|
esac
|
|
4958
5085
|
}
|
|
4959
5086
|
|
|
@@ -6199,6 +6326,288 @@ if [ "$target" = "codex" ]; then
|
|
|
6199
6326
|
exit 0
|
|
6200
6327
|
fi
|
|
6201
6328
|
|
|
6329
|
+
# ---------- Claude Desktop install path (dispatch + exit before the Claude-only writes) ----------
|
|
6330
|
+
#
|
|
6331
|
+
# Claude Desktop sets ANTHROPIC_BASE_URL to Anthropic for its Code tab and
|
|
6332
|
+
# Cowork sessions, so the settings.json route the CLI uses never reaches them.
|
|
6333
|
+
# Both do take the OS proxy and the OS certificate store. So this path:
|
|
6334
|
+
# 1. runs desktop-shim.js as a login service on 127.0.0.1,
|
|
6335
|
+
# 2. trusts a certificate that can only vouch for api.anthropic.com,
|
|
6336
|
+
# 3. points the OS auto-proxy at the shim's PAC file, which sends only
|
|
6337
|
+
# api.anthropic.com to the shim.
|
|
6338
|
+
# The shim sends Desktop's Messages API calls to the router and passes the rest
|
|
6339
|
+
# to Anthropic, so the user's Claude sign-in and subscription are untouched.
|
|
6340
|
+
|
|
6341
|
+
desktop_shim_service_name="weave-router-desktop-shim"
|
|
6342
|
+
desktop_shim_launchd_label="ai.workweave.router-desktop-shim"
|
|
6343
|
+
|
|
6344
|
+
desktop_shim_proxy_url() {
|
|
6345
|
+
printf 'http://127.0.0.1:%s' "$desktop_shim_port"
|
|
6346
|
+
}
|
|
6347
|
+
|
|
6348
|
+
desktop_shim_source() {
|
|
6349
|
+
local candidate
|
|
6350
|
+
[ -n "$script_dir" ] || return 1
|
|
6351
|
+
for candidate in "$script_dir/desktop-shim.js" "$script_dir/../desktop-shim.js"; do
|
|
6352
|
+
if [ -f "$candidate" ]; then
|
|
6353
|
+
printf '%s' "$candidate"
|
|
6354
|
+
return 0
|
|
6355
|
+
fi
|
|
6356
|
+
done
|
|
6357
|
+
return 1
|
|
6358
|
+
}
|
|
6359
|
+
|
|
6360
|
+
# write_desktop_shim_certs makes a CA that may only sign api.anthropic.com,
|
|
6361
|
+
# signs one leaf with it, then deletes the CA key so nothing else can ever be
|
|
6362
|
+
# minted from the CA that Claude Code is told to trust. Re-runs keep a still
|
|
6363
|
+
# valid pair, because the OS already trusts ca.pem.
|
|
6364
|
+
write_desktop_shim_certs() {
|
|
6365
|
+
local dir="$desktop_shim_dir" tmp
|
|
6366
|
+
# An organization can hand every machine the same IT-made pair instead, and
|
|
6367
|
+
# trust that CA through its device management.
|
|
6368
|
+
if [ -n "${WEAVE_DESKTOP_CERT_DIR:-}" ]; then
|
|
6369
|
+
cp "$WEAVE_DESKTOP_CERT_DIR/ca.pem" "$WEAVE_DESKTOP_CERT_DIR/leaf.pem" "$dir/"
|
|
6370
|
+
(umask 077 && cp "$WEAVE_DESKTOP_CERT_DIR/leaf-key.pem" "$dir/leaf-key.pem")
|
|
6371
|
+
return 0
|
|
6372
|
+
fi
|
|
6373
|
+
if [ -f "$dir/ca.pem" ] && [ -f "$dir/leaf.pem" ] && [ -f "$dir/leaf-key.pem" ] \
|
|
6374
|
+
&& openssl verify -CAfile "$dir/ca.pem" "$dir/leaf.pem" >/dev/null 2>&1 \
|
|
6375
|
+
&& openssl x509 -checkend 2592000 -noout -in "$dir/leaf.pem" >/dev/null 2>&1; then
|
|
6376
|
+
return 0
|
|
6377
|
+
fi
|
|
6378
|
+
tmp="$(mktemp -d)"
|
|
6379
|
+
cat >"$tmp/ca.cnf" <<'CNF'
|
|
6380
|
+
[req]
|
|
6381
|
+
distinguished_name = dn
|
|
6382
|
+
prompt = no
|
|
6383
|
+
x509_extensions = v3_ca
|
|
6384
|
+
[dn]
|
|
6385
|
+
CN = Weave Router Claude Desktop proxy
|
|
6386
|
+
[v3_ca]
|
|
6387
|
+
basicConstraints = critical,CA:TRUE,pathlen:0
|
|
6388
|
+
keyUsage = critical,keyCertSign,cRLSign
|
|
6389
|
+
nameConstraints = critical,permitted;DNS:api.anthropic.com
|
|
6390
|
+
subjectKeyIdentifier = hash
|
|
6391
|
+
CNF
|
|
6392
|
+
cat >"$tmp/leaf.ext" <<'EXT'
|
|
6393
|
+
basicConstraints = critical,CA:FALSE
|
|
6394
|
+
keyUsage = critical,digitalSignature,keyEncipherment
|
|
6395
|
+
extendedKeyUsage = serverAuth
|
|
6396
|
+
subjectAltName = DNS:api.anthropic.com
|
|
6397
|
+
authorityKeyIdentifier = keyid
|
|
6398
|
+
EXT
|
|
6399
|
+
if ! {
|
|
6400
|
+
openssl req -x509 -newkey rsa:2048 -nodes -days 825 -config "$tmp/ca.cnf" \
|
|
6401
|
+
-keyout "$tmp/ca-key.pem" -out "$tmp/ca.pem" \
|
|
6402
|
+
&& openssl req -newkey rsa:2048 -nodes -subj "/CN=api.anthropic.com" \
|
|
6403
|
+
-keyout "$tmp/leaf-key.pem" -out "$tmp/leaf.csr" \
|
|
6404
|
+
&& openssl x509 -req -days 825 -in "$tmp/leaf.csr" -CA "$tmp/ca.pem" -CAkey "$tmp/ca-key.pem" \
|
|
6405
|
+
-set_serial "0x$(openssl rand -hex 16)" -extfile "$tmp/leaf.ext" -out "$tmp/leaf.pem"
|
|
6406
|
+
} >/dev/null 2>&1; then
|
|
6407
|
+
rm -rf "$tmp"
|
|
6408
|
+
err "openssl could not create the Claude Desktop proxy certificate."
|
|
6409
|
+
exit 1
|
|
6410
|
+
fi
|
|
6411
|
+
(umask 077 && cp "$tmp/leaf-key.pem" "$dir/leaf-key.pem")
|
|
6412
|
+
cp "$tmp/leaf.pem" "$dir/leaf.pem"
|
|
6413
|
+
cp "$tmp/ca.pem" "$dir/ca.pem"
|
|
6414
|
+
rm -rf "$tmp"
|
|
6415
|
+
ok "Created a local certificate for api.anthropic.com in $dir"
|
|
6416
|
+
}
|
|
6417
|
+
|
|
6418
|
+
write_desktop_shim_config() {
|
|
6419
|
+
local key="$1" tmp
|
|
6420
|
+
tmp="$(mktemp "$desktop_shim_dir/config.json.XXXXXX")"
|
|
6421
|
+
chmod 600 "$tmp"
|
|
6422
|
+
jq -n \
|
|
6423
|
+
--arg base "$base_url" \
|
|
6424
|
+
--arg key "$key" \
|
|
6425
|
+
--argjson port "$desktop_shim_port" \
|
|
6426
|
+
--arg cert "$desktop_shim_dir/leaf.pem" \
|
|
6427
|
+
--arg cert_key "$desktop_shim_dir/leaf-key.pem" \
|
|
6428
|
+
'{listen_host: "127.0.0.1", listen_port: $port, router_base_url: $base, router_key: $key, cert_file: $cert, key_file: $cert_key}' >"$tmp"
|
|
6429
|
+
mv "$tmp" "$desktop_shim_config"
|
|
6430
|
+
}
|
|
6431
|
+
|
|
6432
|
+
xml_escape() {
|
|
6433
|
+
printf '%s' "$1" | sed -e 's/&/\&/g' -e 's/</\</g' -e 's/>/\>/g'
|
|
6434
|
+
}
|
|
6435
|
+
|
|
6436
|
+
start_desktop_shim_service() {
|
|
6437
|
+
local node_bin shim="$desktop_shim_dir/desktop-shim.js"
|
|
6438
|
+
node_bin="$(command -v node)"
|
|
6439
|
+
case "$(uname -s)" in
|
|
6440
|
+
Darwin)
|
|
6441
|
+
local plist="$HOME/Library/LaunchAgents/$desktop_shim_launchd_label.plist" uid
|
|
6442
|
+
local xml_node xml_shim xml_config xml_log
|
|
6443
|
+
uid="$(id -u)"
|
|
6444
|
+
xml_node="$(xml_escape "$node_bin")"
|
|
6445
|
+
xml_shim="$(xml_escape "$shim")"
|
|
6446
|
+
xml_config="$(xml_escape "$desktop_shim_config")"
|
|
6447
|
+
xml_log="$(xml_escape "$desktop_shim_dir/proxy.log")"
|
|
6448
|
+
mkdir -p "$(dirname "$plist")"
|
|
6449
|
+
cat >"$plist" <<PLIST
|
|
6450
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
6451
|
+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
6452
|
+
<plist version="1.0">
|
|
6453
|
+
<dict>
|
|
6454
|
+
<key>Label</key>
|
|
6455
|
+
<string>$desktop_shim_launchd_label</string>
|
|
6456
|
+
<key>ProgramArguments</key>
|
|
6457
|
+
<array>
|
|
6458
|
+
<string>$xml_node</string>
|
|
6459
|
+
<string>$xml_shim</string>
|
|
6460
|
+
<string>$xml_config</string>
|
|
6461
|
+
</array>
|
|
6462
|
+
<key>RunAtLoad</key>
|
|
6463
|
+
<true/>
|
|
6464
|
+
<key>KeepAlive</key>
|
|
6465
|
+
<true/>
|
|
6466
|
+
<key>StandardOutPath</key>
|
|
6467
|
+
<string>$xml_log</string>
|
|
6468
|
+
<key>StandardErrorPath</key>
|
|
6469
|
+
<string>$xml_log</string>
|
|
6470
|
+
</dict>
|
|
6471
|
+
</plist>
|
|
6472
|
+
PLIST
|
|
6473
|
+
launchctl bootout "gui/$uid/$desktop_shim_launchd_label" >/dev/null 2>&1 || true
|
|
6474
|
+
if ! launchctl bootstrap "gui/$uid" "$plist"; then
|
|
6475
|
+
err "launchctl could not start the Claude Desktop proxy from $plist."
|
|
6476
|
+
exit 1
|
|
6477
|
+
fi
|
|
6478
|
+
ok "Claude Desktop proxy runs at login (launchd $desktop_shim_launchd_label)"
|
|
6479
|
+
;;
|
|
6480
|
+
Linux)
|
|
6481
|
+
local unit_dir="${XDG_CONFIG_HOME:-$HOME/.config}/systemd/user" unit
|
|
6482
|
+
unit="$unit_dir/$desktop_shim_service_name.service"
|
|
6483
|
+
mkdir -p "$unit_dir"
|
|
6484
|
+
cat >"$unit" <<UNIT
|
|
6485
|
+
[Unit]
|
|
6486
|
+
Description=Weave Router proxy for Claude Desktop
|
|
6487
|
+
|
|
6488
|
+
[Service]
|
|
6489
|
+
ExecStart="$node_bin" "$shim" "$desktop_shim_config"
|
|
6490
|
+
Restart=always
|
|
6491
|
+
RestartSec=2
|
|
6492
|
+
|
|
6493
|
+
[Install]
|
|
6494
|
+
WantedBy=default.target
|
|
6495
|
+
UNIT
|
|
6496
|
+
if systemctl --user daemon-reload >/dev/null 2>&1 \
|
|
6497
|
+
&& systemctl --user enable "$desktop_shim_service_name.service" >/dev/null 2>&1 \
|
|
6498
|
+
&& systemctl --user restart "$desktop_shim_service_name.service" >/dev/null 2>&1; then
|
|
6499
|
+
ok "Claude Desktop proxy runs at login (systemd --user $desktop_shim_service_name)"
|
|
6500
|
+
else
|
|
6501
|
+
warn "systemctl --user could not start $unit. Start the proxy yourself: \"$node_bin\" \"$shim\" \"$desktop_shim_config\""
|
|
6502
|
+
fi
|
|
6503
|
+
;;
|
|
6504
|
+
*)
|
|
6505
|
+
err "--claude-desktop supports macOS and Linux."
|
|
6506
|
+
exit 1
|
|
6507
|
+
;;
|
|
6508
|
+
esac
|
|
6509
|
+
}
|
|
6510
|
+
|
|
6511
|
+
wait_for_desktop_shim() {
|
|
6512
|
+
local _
|
|
6513
|
+
for _ in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20; do
|
|
6514
|
+
curl -fsS --noproxy '*' --max-time 1 "$(desktop_shim_proxy_url)/health" >/dev/null 2>&1 && return 0
|
|
6515
|
+
sleep 0.25
|
|
6516
|
+
done
|
|
6517
|
+
return 1
|
|
6518
|
+
}
|
|
6519
|
+
|
|
6520
|
+
desktop_shim_ca_store="/usr/local/share/ca-certificates/weave-router-claude-desktop.crt"
|
|
6521
|
+
|
|
6522
|
+
trust_desktop_shim_ca() {
|
|
6523
|
+
case "$(uname -s)" in
|
|
6524
|
+
Darwin)
|
|
6525
|
+
if security verify-cert -c "$desktop_shim_dir/leaf.pem" -p ssl -s api.anthropic.com >/dev/null 2>&1; then
|
|
6526
|
+
return 0
|
|
6527
|
+
fi
|
|
6528
|
+
if [ "$non_interactive" = "true" ]; then
|
|
6529
|
+
warn "macOS shows a password dialog to trust the api.anthropic.com certificate, even with --non-interactive; the install waits for it. Push the CA with device management first to skip it (see install/README.md)."
|
|
6530
|
+
else
|
|
6531
|
+
info "macOS will ask for your password to trust the api.anthropic.com certificate."
|
|
6532
|
+
fi
|
|
6533
|
+
if ! security add-trusted-cert -r trustRoot -k "$HOME/Library/Keychains/login.keychain-db" "$desktop_shim_dir/ca.pem"; then
|
|
6534
|
+
err "Could not trust $desktop_shim_dir/ca.pem in your login keychain."
|
|
6535
|
+
exit 1
|
|
6536
|
+
fi
|
|
6537
|
+
;;
|
|
6538
|
+
Linux)
|
|
6539
|
+
cmp -s "$desktop_shim_dir/ca.pem" "$desktop_shim_ca_store" && return 0
|
|
6540
|
+
info "sudo is needed to add the api.anthropic.com certificate to the system trust store."
|
|
6541
|
+
if ! { sudo install -m 644 "$desktop_shim_dir/ca.pem" "$desktop_shim_ca_store" && sudo update-ca-certificates >/dev/null; }; then
|
|
6542
|
+
err "Could not add $desktop_shim_dir/ca.pem to the system trust store."
|
|
6543
|
+
exit 1
|
|
6544
|
+
fi
|
|
6545
|
+
;;
|
|
6546
|
+
esac
|
|
6547
|
+
ok "Trusted the proxy's api.anthropic.com certificate"
|
|
6548
|
+
}
|
|
6549
|
+
|
|
6550
|
+
# set_desktop_system_proxy leaves an auto-proxy someone else set alone: the PAC
|
|
6551
|
+
# rule to add to it is printed instead.
|
|
6552
|
+
set_desktop_system_proxy() {
|
|
6553
|
+
local pac rule service current
|
|
6554
|
+
pac="http://127.0.0.1:$desktop_shim_port/proxy.pac"
|
|
6555
|
+
rule="if (host === \"api.anthropic.com\") return \"PROXY 127.0.0.1:$desktop_shim_port\";"
|
|
6556
|
+
case "$(uname -s)" in
|
|
6557
|
+
Darwin)
|
|
6558
|
+
while IFS= read -r service; do
|
|
6559
|
+
current="$(networksetup -getautoproxyurl "$service" | sed -n 's/^URL: //p')"
|
|
6560
|
+
[ "$current" = "$pac" ] && continue
|
|
6561
|
+
if [ -n "$current" ] && [ "$current" != "(null)" ]; then
|
|
6562
|
+
warn "$service already uses the auto-proxy $current. Add this rule to it: $rule"
|
|
6563
|
+
continue
|
|
6564
|
+
fi
|
|
6565
|
+
sudo networksetup -setautoproxyurl "$service" "$pac"
|
|
6566
|
+
done < <(networksetup -listallnetworkservices | tail -n +2 | grep -v '^\*')
|
|
6567
|
+
;;
|
|
6568
|
+
Linux)
|
|
6569
|
+
current="$(gsettings get org.gnome.system.proxy autoconfig-url)"
|
|
6570
|
+
if [ "$(gsettings get org.gnome.system.proxy mode)" != "'none'" ] && [ "$current" != "'$pac'" ]; then
|
|
6571
|
+
warn "A system proxy is already set. Add this rule to its PAC file: $rule"
|
|
6572
|
+
return 0
|
|
6573
|
+
fi
|
|
6574
|
+
gsettings set org.gnome.system.proxy autoconfig-url "$pac"
|
|
6575
|
+
gsettings set org.gnome.system.proxy mode 'auto'
|
|
6576
|
+
;;
|
|
6577
|
+
esac
|
|
6578
|
+
ok "System auto-proxy sends api.anthropic.com to $(desktop_shim_proxy_url)"
|
|
6579
|
+
}
|
|
6580
|
+
|
|
6581
|
+
if [ "$target" = "claude-desktop" ]; then
|
|
6582
|
+
desktop_shim_port="${WEAVE_DESKTOP_SHIM_PORT:-$(json_get "$desktop_shim_config" '.listen_port')}"
|
|
6583
|
+
desktop_shim_port="${desktop_shim_port:-47821}"
|
|
6584
|
+
if ! desktop_shim_src="$(desktop_shim_source)"; then
|
|
6585
|
+
err "desktop-shim.js is missing next to the installer. Install with 'npx $npm_package_name --claude-desktop'."
|
|
6586
|
+
exit 1
|
|
6587
|
+
fi
|
|
6588
|
+
cp "$desktop_shim_src" "$desktop_shim_dir/desktop-shim.js"
|
|
6589
|
+
write_desktop_shim_certs
|
|
6590
|
+
write_desktop_shim_config "$api_key"
|
|
6591
|
+
ok "Proxy config written to $desktop_shim_config"
|
|
6592
|
+
start_desktop_shim_service
|
|
6593
|
+
if wait_for_desktop_shim; then
|
|
6594
|
+
ok "Claude Desktop proxy is listening on $(desktop_shim_proxy_url)"
|
|
6595
|
+
else
|
|
6596
|
+
warn "The Claude Desktop proxy isn't answering on $(desktop_shim_proxy_url) yet. Check $desktop_shim_dir/proxy.log (macOS) or 'journalctl --user -u $desktop_shim_service_name' (Linux)."
|
|
6597
|
+
fi
|
|
6598
|
+
trust_desktop_shim_ca
|
|
6599
|
+
set_desktop_system_proxy
|
|
6600
|
+
|
|
6601
|
+
verify_install
|
|
6602
|
+
|
|
6603
|
+
announce_done "Claude Desktop"
|
|
6604
|
+
if [ "$mode" = "install" ] && [ "$quiet" != "true" ]; then
|
|
6605
|
+
printf "\n%sNext:%s quit and reopen Claude Desktop. New Code sessions, and Cowork tasks that run on this computer, go through Weave Router; Cowork tasks running in Anthropic's cloud do not. You stay signed in to Claude.\n" "$C_BOLD" "$C_RESET"
|
|
6606
|
+
fi
|
|
6607
|
+
[ "$mode" = "update" ] || print_uninstall_hint
|
|
6608
|
+
exit 0
|
|
6609
|
+
fi
|
|
6610
|
+
|
|
6202
6611
|
# ---------- copilot install path (dispatch + exit before the Claude-only writes) ----------
|
|
6203
6612
|
|
|
6204
6613
|
if [ "$target" = "copilot" ]; then
|
|
@@ -6726,6 +7135,9 @@ weave_hidden_gate() {
|
|
|
6726
7135
|
local cache="$cache_dir/display-settings${script_slug}"
|
|
6727
7136
|
local ttl="${WEAVE_DISPLAY_SETTINGS_TTL_SECONDS:-3600}"
|
|
6728
7137
|
|
|
7138
|
+
# Linked plans that need a fresh login, from the last successful refresh.
|
|
7139
|
+
weave_disconnected_plans="$(cat "$cache.plans" 2>/dev/null)"
|
|
7140
|
+
|
|
6729
7141
|
local now mtime fresh="false"
|
|
6730
7142
|
now="$(date +%s 2>/dev/null)" || now=0
|
|
6731
7143
|
if [ -f "$cache" ]; then
|
|
@@ -6825,6 +7237,8 @@ weave_hidden_gate() {
|
|
|
6825
7237
|
else
|
|
6826
7238
|
printf '0' >"$tmp" 2>/dev/null && mv "$tmp" "$cache" 2>/dev/null
|
|
6827
7239
|
fi
|
|
7240
|
+
plans="$(printf '%s' "$body" | jq -r '[.disconnected_plans[]? | select(type == "string" and test("^[a-z]+$"))] | join(" ")' 2>/dev/null)"
|
|
7241
|
+
printf '%s' "$plans" >"$tmp" 2>/dev/null && mv "$tmp" "$cache.plans" 2>/dev/null
|
|
6828
7242
|
rm -f "$tmp" 2>/dev/null
|
|
6829
7243
|
) >/dev/null 2>&1 &
|
|
6830
7244
|
disown 2>/dev/null || true
|
|
@@ -7434,7 +7848,8 @@ brand=$'\033[38;2;255;108;71mWEAVE ROUTER\033[0m'
|
|
|
7434
7848
|
# saving.
|
|
7435
7849
|
short_model() { printf '%s' "${1#claude-}"; }
|
|
7436
7850
|
picked=""
|
|
7437
|
-
|
|
7851
|
+
# Weave Auto is a routing choice, not a model, so only the served model is shown.
|
|
7852
|
+
if [[ -n "$selected_display" && "$selected_display" != "?" && "$requested_norm" != "weave-auto" ]]; then
|
|
7438
7853
|
picked="$(short_model "$requested_norm")"
|
|
7439
7854
|
fi
|
|
7440
7855
|
status_text=""
|
|
@@ -7465,6 +7880,27 @@ if [[ "$has_pin_record" == "true" ]]; then
|
|
|
7465
7880
|
status_text="$status_text · last pin: $last_pin_model"
|
|
7466
7881
|
fi
|
|
7467
7882
|
|
|
7883
|
+
# Point the reconnect command at this install: a bare login reads the
|
|
7884
|
+
# user-scope config, which a project or --dir install doesn't use.
|
|
7885
|
+
weave_login_scope=""
|
|
7886
|
+
if [ -n "${weave_disconnected_plans:-}" ]; then
|
|
7887
|
+
weave_sl_dir="$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" 2>/dev/null && pwd)"
|
|
7888
|
+
case "$weave_sl_dir" in
|
|
7889
|
+
*/.claude)
|
|
7890
|
+
weave_login_scope=" --dir $(printf '%q' "${weave_sl_dir%/.claude}")"
|
|
7891
|
+
if grep -q 'X-Weave-Router-Key' "$weave_sl_dir/settings.local.json" 2>/dev/null; then
|
|
7892
|
+
weave_login_scope=" --scope project$weave_login_scope"
|
|
7893
|
+
fi
|
|
7894
|
+
;;
|
|
7895
|
+
esac
|
|
7896
|
+
fi
|
|
7897
|
+
for weave_plan in ${weave_disconnected_plans:-}; do
|
|
7898
|
+
case "$weave_plan" in
|
|
7899
|
+
claude) status_text="$status_text · Claude plan disconnected: run npx @weave-os/router login claude$weave_login_scope" ;;
|
|
7900
|
+
codex) status_text="$status_text · Codex plan disconnected: run npx @weave-os/router login codex$weave_login_scope" ;;
|
|
7901
|
+
esac
|
|
7902
|
+
done
|
|
7903
|
+
|
|
7468
7904
|
# /router-status reads this back through the prompt hook, so it can answer
|
|
7469
7905
|
# without a model turn.
|
|
7470
7906
|
weave_cache_status_line() {
|
|
@@ -7508,6 +7944,15 @@ trap '_spin_cleanup; rm -f "$tmp_patch"' EXIT INT TERM HUP
|
|
|
7508
7944
|
write_claude_settings() {
|
|
7509
7945
|
local block_key="$1"
|
|
7510
7946
|
prepare_claude_context_window
|
|
7947
|
+
# Before passthrough every model was routed, so a model saved back then was
|
|
7948
|
+
# never a pin. Move those installs (and new ones) to Weave Auto once; later
|
|
7949
|
+
# updates keep whatever the user picks.
|
|
7950
|
+
# --context-window pins its own [1m] model, so it is never overridden.
|
|
7951
|
+
local weave_auto_rollout="true"
|
|
7952
|
+
if [ -n "$context_window" ] || [ -f "$settings_dir/.weave-context-window.json" ] \
|
|
7953
|
+
|| claude_passthrough_installed "$context_settings_file" "$settings_file"; then
|
|
7954
|
+
weave_auto_rollout="false"
|
|
7955
|
+
fi
|
|
7511
7956
|
|
|
7512
7957
|
# Claude Code splits ANTHROPIC_CUSTOM_HEADERS on newlines, so multiple headers
|
|
7513
7958
|
# ride in the same env var separated by \n. Append identity headers alongside
|
|
@@ -7521,7 +7966,7 @@ write_claude_settings() {
|
|
|
7521
7966
|
if [ -n "$user_name" ]; then
|
|
7522
7967
|
custom_headers="$custom_headers"$'\n'"X-Weave-User-Name: $user_name"
|
|
7523
7968
|
fi
|
|
7524
|
-
custom_headers="$custom_headers"$'\n'"X-App: claude-code"
|
|
7969
|
+
custom_headers="$custom_headers"$'\n'"X-App: claude-code"$'\n'"X-Weave-Model-Passthrough: 1"
|
|
7525
7970
|
|
|
7526
7971
|
# Setting ANTHROPIC_BASE_URL makes Claude Code treat us as non-first-party.
|
|
7527
7972
|
# Force tool-search deferral to match first-party Claude Code; "auto" can inline
|
|
@@ -7612,6 +8057,16 @@ write_claude_settings() {
|
|
|
7612
8057
|
chmod 600 "$local_settings_file"
|
|
7613
8058
|
ok "Router key header written to $local_settings_file"
|
|
7614
8059
|
fi
|
|
8060
|
+
local weave_auto_default="false"
|
|
8061
|
+
if [ "$weave_auto_rollout" = "true" ]; then
|
|
8062
|
+
weave_auto_default="force"
|
|
8063
|
+
if [ -n "${ANTHROPIC_MODEL:-}" ]; then
|
|
8064
|
+
warn "ANTHROPIC_MODEL=$ANTHROPIC_MODEL in your shell pins that model and skips Weave routing. Unset it to use Weave Auto."
|
|
8065
|
+
fi
|
|
8066
|
+
elif claude_model_unset "$context_settings_file" "$settings_file" "$HOME/.claude/settings.json"; then
|
|
8067
|
+
weave_auto_default="true"
|
|
8068
|
+
fi
|
|
8069
|
+
apply_claude_weave_auto "$context_settings_file" "$weave_auto_default"
|
|
7615
8070
|
context_window_action="install"
|
|
7616
8071
|
if [ "$mode" = "update" ] && [ ! -f "$settings_dir/.weave-parked.json" ]; then
|
|
7617
8072
|
context_window_action="update"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@weave-os/router",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.33",
|
|
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",
|
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
"windows.js",
|
|
20
20
|
"install.sh",
|
|
21
21
|
"uninstall.sh",
|
|
22
|
+
"desktop-shim.js",
|
|
22
23
|
"cc-statusline.sh",
|
|
23
24
|
"codex-status.sh",
|
|
24
25
|
"codex-toggle.sh",
|
package/uninstall.sh
CHANGED
|
@@ -151,6 +151,13 @@ EOF
|
|
|
151
151
|
target="claude"
|
|
152
152
|
|
|
153
153
|
CLAUDE_STATUSLINE_MARKER="# Claude Code statusline for the Weave Router."
|
|
154
|
+
# Mirrors install.sh: removes only the Weave Auto picker row and default.
|
|
155
|
+
CLAUDE_WEAVE_AUTO_STRIP_JQ='(if (.model == "weave-auto" or .model == "weave-auto[1m]") then del(.model) else . end)
|
|
156
|
+
| (if (.modelPicker | type) == "object" then
|
|
157
|
+
.modelPicker.options = ((.modelPicker.options // []) | map(select(.model != "weave-auto" and .model != "weave-auto[1m]")))
|
|
158
|
+
| (if (.modelPicker.options | length) == 0 then del(.modelPicker.options) else . end)
|
|
159
|
+
| (if (.modelPicker | length) == 0 then del(.modelPicker) else . end)
|
|
160
|
+
else . end)'
|
|
154
161
|
|
|
155
162
|
err() { printf "\033[31merror:\033[0m %s\n" "$*" >&2; }
|
|
156
163
|
warn() { printf "\033[33mwarning:\033[0m %s\n" "$*" >&2; }
|
|
@@ -263,6 +270,9 @@ while [ $# -gt 0 ]; do
|
|
|
263
270
|
--copilot)
|
|
264
271
|
target="copilot"; target_explicit="true"; shift
|
|
265
272
|
;;
|
|
273
|
+
--claude-desktop)
|
|
274
|
+
target="claude-desktop"; target_explicit="true"; shift
|
|
275
|
+
;;
|
|
266
276
|
--claude)
|
|
267
277
|
# No-op selector for symmetry with --codex / --opencode and install.sh's
|
|
268
278
|
# --claude. Lets `./install.sh --uninstall --claude` (which forwards
|
|
@@ -299,6 +309,7 @@ client_label() {
|
|
|
299
309
|
claude) printf 'Claude Code' ;;
|
|
300
310
|
codex) printf 'Codex' ;;
|
|
301
311
|
copilot) printf 'Copilot CLI' ;;
|
|
312
|
+
claude-desktop) printf 'Claude Desktop' ;;
|
|
302
313
|
*) printf '%s' "$1" ;;
|
|
303
314
|
esac
|
|
304
315
|
}
|
|
@@ -318,7 +329,7 @@ if [ "$target_explicit" = "false" ] && [ -z "${WEAVE_UNINSTALL_ALL_CHILD:-}" ] \
|
|
|
318
329
|
fi
|
|
319
330
|
removed=""
|
|
320
331
|
failed=""
|
|
321
|
-
for client in claude codex opencode pi copilot; do
|
|
332
|
+
for client in claude codex opencode pi copilot claude-desktop; do
|
|
322
333
|
child_status=0
|
|
323
334
|
WEAVE_UNINSTALL_ALL_CHILD=1 bash "$uninstall_self" "${uninstall_args[@]+"${uninstall_args[@]}"}" "--$client" || child_status=$?
|
|
324
335
|
case "$child_status" in
|
|
@@ -330,7 +341,7 @@ if [ "$target_explicit" = "false" ] && [ -z "${WEAVE_UNINSTALL_ALL_CHILD:-}" ] \
|
|
|
330
341
|
[ -z "$uninstall_self_tmp" ] || rm -f "$uninstall_self_tmp"
|
|
331
342
|
printf '\n'
|
|
332
343
|
if [ -z "$removed" ] && [ -z "$failed" ]; then
|
|
333
|
-
info "Weave Router isn't configured for Claude Code, Codex, opencode, pi
|
|
344
|
+
info "Weave Router isn't configured for Claude Code, Codex, opencode, pi, Copilot CLI or Claude Desktop here (scope=$scope); nothing to remove."
|
|
334
345
|
fi
|
|
335
346
|
[ -z "$removed" ] || ok "Removed Weave Router from: $removed."
|
|
336
347
|
if [ -n "$failed" ]; then
|
|
@@ -345,6 +356,77 @@ if [ -z "${WEAVE_UNINSTALL_ALL_CHILD:-}" ] && { [ "$target" = "claude" ] || [ "$
|
|
|
345
356
|
exit 1
|
|
346
357
|
fi
|
|
347
358
|
|
|
359
|
+
# Claude Desktop runs through a local proxy service (see install.sh); remove the
|
|
360
|
+
# service, its certificate and the stored router key.
|
|
361
|
+
if [ "$target" = "claude-desktop" ]; then
|
|
362
|
+
if [ "$scope" = "project" ]; then
|
|
363
|
+
[ -z "${WEAVE_UNINSTALL_ALL_CHILD:-}" ] || exit 3
|
|
364
|
+
err "--claude-desktop installs in user scope only; drop --scope project."
|
|
365
|
+
exit 2
|
|
366
|
+
fi
|
|
367
|
+
desktop_shim_dir="${install_dir:-$HOME}/.weave-router/desktop-shim"
|
|
368
|
+
desktop_shim_config="$desktop_shim_dir/config.json"
|
|
369
|
+
desktop_shim_plist="$HOME/Library/LaunchAgents/ai.workweave.router-desktop-shim.plist"
|
|
370
|
+
desktop_shim_unit="${XDG_CONFIG_HOME:-$HOME/.config}/systemd/user/weave-router-desktop-shim.service"
|
|
371
|
+
skip_if_not_installed "$desktop_shim_config" 'router_base_url'
|
|
372
|
+
# The service files live under $HOME whatever --dir says; only remove the ones
|
|
373
|
+
# that run this install's config.
|
|
374
|
+
desktop_shim_config_xml="$(printf '%s' "$desktop_shim_config" | sed -e 's/&/\&/g' -e 's/</\</g' -e 's/>/\>/g')"
|
|
375
|
+
if [ -f "$desktop_shim_plist" ] && grep -Fq "<string>$desktop_shim_config_xml</string>" "$desktop_shim_plist"; then
|
|
376
|
+
launchctl bootout "gui/$(id -u)/ai.workweave.router-desktop-shim" >/dev/null 2>&1 || true
|
|
377
|
+
rm -f "$desktop_shim_plist"
|
|
378
|
+
ok "Removed $desktop_shim_plist"
|
|
379
|
+
fi
|
|
380
|
+
if [ -f "$desktop_shim_unit" ] && grep -Fq "\"$desktop_shim_config\"" "$desktop_shim_unit"; then
|
|
381
|
+
systemctl --user disable --now weave-router-desktop-shim.service >/dev/null 2>&1 || true
|
|
382
|
+
rm -f "$desktop_shim_unit"
|
|
383
|
+
systemctl --user daemon-reload >/dev/null 2>&1 || true
|
|
384
|
+
ok "Removed $desktop_shim_unit"
|
|
385
|
+
fi
|
|
386
|
+
# Undo the trusted certificate and the auto-proxy, but only where they are this install's.
|
|
387
|
+
desktop_shim_pac="http://127.0.0.1:$(jq -r '.listen_port // 47821' "$desktop_shim_config" 2>/dev/null || echo 47821)/proxy.pac"
|
|
388
|
+
case "$(uname -s)" in
|
|
389
|
+
Darwin)
|
|
390
|
+
if [ -f "$desktop_shim_dir/ca.pem" ] \
|
|
391
|
+
&& security find-certificate -c "Weave Router Claude Desktop proxy" "$HOME/Library/Keychains/login.keychain-db" >/dev/null 2>&1; then
|
|
392
|
+
if ! security remove-trusted-cert "$desktop_shim_dir/ca.pem" \
|
|
393
|
+
|| ! security delete-certificate -Z "$(openssl x509 -noout -fingerprint -sha1 -in "$desktop_shim_dir/ca.pem" | sed 's/.*=//; s/://g')" \
|
|
394
|
+
"$HOME/Library/Keychains/login.keychain-db" >/dev/null; then
|
|
395
|
+
desktop_shim_ca_left="true"
|
|
396
|
+
fi
|
|
397
|
+
fi
|
|
398
|
+
while IFS= read -r service; do
|
|
399
|
+
if [ "$(networksetup -getautoproxyurl "$service" | sed -n 's/^URL: //p')" = "$desktop_shim_pac" ]; then
|
|
400
|
+
sudo networksetup -setautoproxystate "$service" off
|
|
401
|
+
fi
|
|
402
|
+
done < <(networksetup -listallnetworkservices | tail -n +2 | grep -v '^\*')
|
|
403
|
+
;;
|
|
404
|
+
Linux)
|
|
405
|
+
desktop_shim_ca_store="/usr/local/share/ca-certificates/weave-router-claude-desktop.crt"
|
|
406
|
+
if [ -f "$desktop_shim_ca_store" ] && cmp -s "$desktop_shim_dir/ca.pem" "$desktop_shim_ca_store"; then
|
|
407
|
+
if ! { sudo rm -f "$desktop_shim_ca_store" && sudo update-ca-certificates --fresh >/dev/null; }; then
|
|
408
|
+
desktop_shim_ca_left="true"
|
|
409
|
+
fi
|
|
410
|
+
fi
|
|
411
|
+
if [ "$(gsettings get org.gnome.system.proxy autoconfig-url 2>/dev/null)" = "'$desktop_shim_pac'" ]; then
|
|
412
|
+
gsettings set org.gnome.system.proxy mode 'none'
|
|
413
|
+
gsettings reset org.gnome.system.proxy autoconfig-url
|
|
414
|
+
fi
|
|
415
|
+
;;
|
|
416
|
+
esac
|
|
417
|
+
# Keep ca.pem and the config while the OS still trusts the CA, so a rerun can remove it.
|
|
418
|
+
if [ "${desktop_shim_ca_left:-}" = "true" ]; then
|
|
419
|
+
warn "Could not remove the proxy certificate from the OS trust store (a cancelled password prompt?). Rerun: npx @weave-os/router --uninstall --claude-desktop"
|
|
420
|
+
elif [ -d "$desktop_shim_dir" ]; then
|
|
421
|
+
refuse_if_symlink "$desktop_shim_dir"
|
|
422
|
+
rm -rf "$desktop_shim_dir"
|
|
423
|
+
rmdir "$(dirname "$desktop_shim_dir")" 2>/dev/null || true
|
|
424
|
+
ok "Removed $desktop_shim_dir"
|
|
425
|
+
fi
|
|
426
|
+
info "Quit and reopen Claude Desktop so new sessions go direct to Anthropic."
|
|
427
|
+
exit 0
|
|
428
|
+
fi
|
|
429
|
+
|
|
348
430
|
# ---------- lifecycle report ----------
|
|
349
431
|
#
|
|
350
432
|
# report_uninstall_event tells this install's router that the uninstall is
|
|
@@ -1335,7 +1417,7 @@ if [ -f "$settings_file" ]; then
|
|
|
1335
1417
|
# delete `statusLine` / `apiKeyHelper` when they point at scripts this
|
|
1336
1418
|
# installer used in older versions. Otherwise an unrelated user-configured
|
|
1337
1419
|
# statusLine or apiKeyHelper would be silently clobbered.
|
|
1338
|
-
cleaned="$(jq --arg statusline_setting_owned "$statusline_setting_owned" '
|
|
1420
|
+
cleaned="$(jq --arg statusline_setting_owned "$statusline_setting_owned" "$CLAUDE_WEAVE_AUTO_STRIP_JQ"' |
|
|
1339
1421
|
if .env then
|
|
1340
1422
|
.env |= (del(.ANTHROPIC_BASE_URL, .ANTHROPIC_AUTH_TOKEN, .ANTHROPIC_CUSTOM_HEADERS, .ENABLE_TOOL_SEARCH))
|
|
1341
1423
|
| (if (.env | length) == 0 then del(.env) else . end)
|
|
@@ -1366,7 +1448,7 @@ if [ -n "$local_settings_file" ] && [ -f "$local_settings_file" ]; then
|
|
|
1366
1448
|
# (the off path overrides it to Anthropic in the local file). Project installs
|
|
1367
1449
|
# also keep WEAVE_ROUTER_BASE_URL here as a private endpoint marker beside the
|
|
1368
1450
|
# router key; scrub both so uninstall fully reverts the local config.
|
|
1369
|
-
cleaned="$(jq '
|
|
1451
|
+
cleaned="$(jq "$CLAUDE_WEAVE_AUTO_STRIP_JQ"' |
|
|
1370
1452
|
if .env then
|
|
1371
1453
|
.env |= (del(.ANTHROPIC_BASE_URL, .ANTHROPIC_AUTH_TOKEN, .ANTHROPIC_CUSTOM_HEADERS, .ENABLE_TOOL_SEARCH, .WEAVE_ROUTER_BASE_URL))
|
|
1372
1454
|
| (if (.env | length) == 0 then del(.env) else . end)
|
package/windows.js
CHANGED
|
@@ -216,6 +216,21 @@ async function ensureProjectFilesPrivate(root, target) {
|
|
|
216
216
|
return trackedProjectPaths;
|
|
217
217
|
}
|
|
218
218
|
|
|
219
|
+
// Claude Code sends a picker model ID verbatim (minus [1m], which it turns into
|
|
220
|
+
// the 1M-context beta); the router routes only weave-auto and serves every other
|
|
221
|
+
// model as-is (X-Weave-Model-Passthrough).
|
|
222
|
+
const claudeWeaveAutoModel = "weave-auto[1m]";
|
|
223
|
+
const isClaudeWeaveAuto = (model) => model === "weave-auto" || model === claudeWeaveAutoModel;
|
|
224
|
+
const claudeWeaveAutoOption = { model: claudeWeaveAutoModel, label: "Weave Auto", description: "Weave picks the best model for each turn", behavesAs: "claude-opus-5-5" };
|
|
225
|
+
|
|
226
|
+
function stripClaudeWeaveAuto(layer) {
|
|
227
|
+
if (isClaudeWeaveAuto(layer.model)) delete layer.model;
|
|
228
|
+
if (!layer.modelPicker || typeof layer.modelPicker !== "object") return;
|
|
229
|
+
layer.modelPicker.options = (layer.modelPicker.options || []).filter((option) => !isClaudeWeaveAuto(option?.model));
|
|
230
|
+
if (!layer.modelPicker.options.length) delete layer.modelPicker.options;
|
|
231
|
+
if (!Object.keys(layer.modelPicker).length) delete layer.modelPicker;
|
|
232
|
+
}
|
|
233
|
+
|
|
219
234
|
function installClaude(paths, baseUrl, key, email, attribution) {
|
|
220
235
|
const settings = readJson(paths.config);
|
|
221
236
|
// Same rule as install.sh: an install without our attribution block is an opt-out that reinstalls keep.
|
|
@@ -231,11 +246,15 @@ function installClaude(paths, baseUrl, key, email, attribution) {
|
|
|
231
246
|
};
|
|
232
247
|
state.installedBaseUrl = baseUrl;
|
|
233
248
|
const customHeaders = localSettings?.env?.ANTHROPIC_CUSTOM_HEADERS ?? settings.env?.ANTHROPIC_CUSTOM_HEADERS ?? "";
|
|
234
|
-
|
|
249
|
+
// Before passthrough every model was routed, so a saved model was never a pin:
|
|
250
|
+
// move those installs (and new ones) to Weave Auto once, then keep the user's picks.
|
|
251
|
+
const weaveAutoRollout = ![settings, localSettings].some((layer) => /^X-Weave-Model-Passthrough:/im.test(layer?.env?.ANTHROPIC_CUSTOM_HEADERS || ""));
|
|
252
|
+
const previousHeaders = customHeaders.split("\n").filter((header) => !/^X-(?:Weave-Router-Key|Weave-User-Email|Weave-User-Name|Weave-Model-Passthrough|App):/i.test(header));
|
|
235
253
|
const routerHeaders = [
|
|
236
254
|
`X-Weave-Router-Key: ${key}`,
|
|
237
255
|
...(email ? [`X-Weave-User-Email: ${email}`] : []),
|
|
238
256
|
"X-App: claude-code",
|
|
257
|
+
"X-Weave-Model-Passthrough: 1",
|
|
239
258
|
];
|
|
240
259
|
settings.env ||= {};
|
|
241
260
|
settings.env.ANTHROPIC_BASE_URL = baseUrl;
|
|
@@ -247,6 +266,14 @@ function installClaude(paths, baseUrl, key, email, attribution) {
|
|
|
247
266
|
settings.env.ANTHROPIC_CUSTOM_HEADERS = [...previousHeaders, ...routerHeaders].filter(Boolean).join("\n");
|
|
248
267
|
}
|
|
249
268
|
settings.env.ENABLE_TOOL_SEARCH = "true";
|
|
269
|
+
const modelSettings = localSettings || settings;
|
|
270
|
+
const modelUnset = !process.env.ANTHROPIC_MODEL && [settings, localSettings, readJson(path.join(process.env.USERPROFILE || process.env.HOME, ".claude", "settings.json"))].every((layer) => !layer || (!Object.hasOwn(layer, "model") && !layer.env?.ANTHROPIC_MODEL));
|
|
271
|
+
modelSettings.modelPicker = { ...(modelSettings.modelPicker || {}) };
|
|
272
|
+
modelSettings.modelPicker.options = [claudeWeaveAutoOption, ...(modelSettings.modelPicker.options || []).filter((option) => !isClaudeWeaveAuto(option?.model))];
|
|
273
|
+
if (weaveAutoRollout) {
|
|
274
|
+
modelSettings.model = claudeWeaveAutoModel;
|
|
275
|
+
if (modelSettings.env) delete modelSettings.env.ANTHROPIC_MODEL;
|
|
276
|
+
} else if (modelUnset || modelSettings.model === "weave-auto") modelSettings.model = claudeWeaveAutoModel;
|
|
250
277
|
if (attribution && (ownsAttribution || (settings.attribution == null && !optedOutOfAttribution))) {
|
|
251
278
|
settings.attribution = { ...claudeAttribution, ...settings.attribution, commit: claudeAttribution.commit };
|
|
252
279
|
} else if (!attribution && ownsAttribution) {
|
|
@@ -274,11 +301,13 @@ function installCodex(paths, baseUrl, key, email) {
|
|
|
274
301
|
base_url: `${baseUrl}/v1`,
|
|
275
302
|
wire_api: "responses",
|
|
276
303
|
requires_openai_auth: true,
|
|
304
|
+
model_catalog_url: `${baseUrl}/v1/codex/models`,
|
|
277
305
|
http_headers: {
|
|
278
306
|
"X-Weave-Router-Key": key,
|
|
279
307
|
...(email ? { "X-Weave-User-Email": email } : {}),
|
|
280
308
|
"X-App": "codex",
|
|
281
309
|
"X-Weave-Codex-Native-Model-Pin": "1",
|
|
310
|
+
"X-Weave-Codex-Model-Catalog": "1",
|
|
282
311
|
},
|
|
283
312
|
};
|
|
284
313
|
writeToml(paths.config, settings);
|
|
@@ -363,8 +392,9 @@ function uninstall(paths, target) {
|
|
|
363
392
|
if (!fs.existsSync(paths.state) && ![settings.env?.ANTHROPIC_CUSTOM_HEADERS, localSettings?.env?.ANTHROPIC_CUSTOM_HEADERS].some((headers) => /^X-Weave-Router-Key:/m.test(headers || ""))) return;
|
|
364
393
|
restoreField(settings.env, "ANTHROPIC_BASE_URL", state.env?.ANTHROPIC_BASE_URL, state.installedBaseUrl || settings.env?.ANTHROPIC_BASE_URL);
|
|
365
394
|
restoreField(settings.env, "ENABLE_TOOL_SEARCH", state.env?.ENABLE_TOOL_SEARCH, "true");
|
|
395
|
+
for (const layer of [settings, localSettings]) if (layer) stripClaudeWeaveAuto(layer);
|
|
366
396
|
const customHeaders = (headerBlock, originalAppHeaders) => {
|
|
367
|
-
const preservedHeaders = (headerBlock || "").split("\n").filter((header) => !/^X-Weave-(?:Router-Key|User-Email|User-Name):/i.test(header) && !/^X-App:\s*claude-code\s*$/i.test(header));
|
|
397
|
+
const preservedHeaders = (headerBlock || "").split("\n").filter((header) => !/^X-Weave-(?:Router-Key|User-Email|User-Name|Model-Passthrough):/i.test(header) && !/^X-App:\s*claude-code\s*$/i.test(header));
|
|
368
398
|
if (!preservedHeaders.some((header) => /^X-App:/i.test(header))) preservedHeaders.push(...(originalAppHeaders || []));
|
|
369
399
|
return preservedHeaders.filter(Boolean).join("\n");
|
|
370
400
|
};
|