@hasna/switcher 0.2.14 → 0.2.16
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/dist/claude-desktop.js +85 -16
- package/dist/claude-user-settings.d.ts +7 -2
- package/dist/cli/index.js +193 -60
- package/dist/mcp/index.js +2 -2
- package/dist/native-state.d.ts +17 -0
- package/dist/serve/index.js +2 -2
- package/openapi.json +1 -1
- package/package.json +5 -2
package/dist/claude-desktop.js
CHANGED
|
@@ -4225,7 +4225,8 @@ async function discoverClaudeDesktopModels(base, token, fetcher) {
|
|
|
4225
4225
|
// src/native-state.ts
|
|
4226
4226
|
import { lstat, mkdir, open, opendir, readlink, realpath, rmdir, symlink, unlink } from "node:fs/promises";
|
|
4227
4227
|
import { constants, lstatSync, realpathSync } from "node:fs";
|
|
4228
|
-
import {
|
|
4228
|
+
import { execFileSync } from "node:child_process";
|
|
4229
|
+
import { homedir, userInfo } from "node:os";
|
|
4229
4230
|
import { dirname, isAbsolute, join, relative, resolve } from "node:path";
|
|
4230
4231
|
var CODEX_INSTRUCTION_KEYS = [
|
|
4231
4232
|
"instructions",
|
|
@@ -4264,29 +4265,74 @@ function absolute(value) {
|
|
|
4264
4265
|
throw new Fault(422, "native_state_path", "The shared native state directory must be an absolute path.");
|
|
4265
4266
|
return resolve(value);
|
|
4266
4267
|
}
|
|
4268
|
+
function displayPath(path) {
|
|
4269
|
+
const value = JSON.stringify(path).replace(/[\u007f-\u009f\u061c\u200e\u200f\u2028-\u202e\u2066-\u2069]/g, (character) => `\\u${character.charCodeAt(0).toString(16).padStart(4, "0")}`);
|
|
4270
|
+
return value.length > 768 ? `${value.slice(0, 384)}...${value.slice(-381)}` : value;
|
|
4271
|
+
}
|
|
4272
|
+
function isUserPrivateGroup(gid, user, group, passwd) {
|
|
4273
|
+
if (gid === 0 || user.uid === 0 || gid !== user.gid)
|
|
4274
|
+
return false;
|
|
4275
|
+
const groups = group.split(`
|
|
4276
|
+
`).filter(Boolean);
|
|
4277
|
+
if (groups.length !== 1)
|
|
4278
|
+
return false;
|
|
4279
|
+
const [groupName, , groupId, members = "", ...extra] = groups[0].split(":");
|
|
4280
|
+
if (extra.length || groupName !== user.name || Number(groupId) !== gid || members.split(",").some((member) => member !== "" && member !== user.name))
|
|
4281
|
+
return false;
|
|
4282
|
+
const accounts = passwd.split(`
|
|
4283
|
+
`).filter(Boolean).map((line) => line.split(":"));
|
|
4284
|
+
if (accounts.some((fields) => fields.length < 4 || !/^\d+$/.test(fields[3] ?? "")))
|
|
4285
|
+
return false;
|
|
4286
|
+
const primary = accounts.filter((fields) => Number(fields[3]) === gid);
|
|
4287
|
+
return primary.length === 1 && primary[0][0] === user.name && Number(primary[0][2]) === user.uid;
|
|
4288
|
+
}
|
|
4289
|
+
function probeUserPrivateGroup(gid) {
|
|
4290
|
+
if (process.platform !== "linux")
|
|
4291
|
+
return false;
|
|
4292
|
+
try {
|
|
4293
|
+
const run = (args) => execFileSync("getent", args, { encoding: "utf8", timeout: 5000, stdio: ["ignore", "pipe", "ignore"] });
|
|
4294
|
+
return isUserPrivateGroup(gid, { uid: process.getuid(), gid: process.getgid(), name: userInfo().username }, run(["group", String(gid)]), run(["passwd"]));
|
|
4295
|
+
} catch {
|
|
4296
|
+
return false;
|
|
4297
|
+
}
|
|
4298
|
+
}
|
|
4299
|
+
var privateGroupProbe = probeUserPrivateGroup;
|
|
4300
|
+
var privateGroupAnswers = new Map;
|
|
4301
|
+
function userPrivateGroup(gid) {
|
|
4302
|
+
let answer = privateGroupAnswers.get(gid);
|
|
4303
|
+
if (answer === undefined) {
|
|
4304
|
+
answer = privateGroupProbe(gid);
|
|
4305
|
+
privateGroupAnswers.set(gid, answer);
|
|
4306
|
+
}
|
|
4307
|
+
return answer;
|
|
4308
|
+
}
|
|
4309
|
+
function writableByOthers(entry) {
|
|
4310
|
+
return (entry.mode & 2) !== 0 || (entry.mode & 16) !== 0 && !userPrivateGroup(entry.gid);
|
|
4311
|
+
}
|
|
4312
|
+
var writeFix = "Remove group and other write permission (chmod go-w), or on Linux keep group write only for your own private group";
|
|
4267
4313
|
function credentialOverlay(path) {
|
|
4268
4314
|
return /(?:^|\/)subscriptions\/profiles\//.test(path) || /(?:^|\/)switcher\/state\/(?:desktop|desktop-claude|launch-[^/]+)\//.test(path);
|
|
4269
4315
|
}
|
|
4270
|
-
function assertSafeAncestor(ancestor) {
|
|
4316
|
+
function assertSafeAncestor(ancestor, path) {
|
|
4271
4317
|
const stickyRoot = ancestor.uid === 0 && (ancestor.mode & 512) !== 0;
|
|
4272
|
-
if (!ancestor.isDirectory() || ancestor.isSymbolicLink() || ![0, process.getuid?.()].includes(ancestor.uid) || (ancestor
|
|
4273
|
-
throw new Fault(422, "native_state_permissions",
|
|
4318
|
+
if (!ancestor.isDirectory() || ancestor.isSymbolicLink() || ![0, process.getuid?.()].includes(ancestor.uid) || writableByOthers(ancestor) && !stickyRoot)
|
|
4319
|
+
throw new Fault(422, "native_state_permissions", `Shared native state has an unsafe ancestor directory ${displayPath(path)}. Each ancestor must be a real directory owned by you or root and not writable by other users. ${writeFix}.`);
|
|
4274
4320
|
}
|
|
4275
4321
|
async function assertSafeAncestors(path) {
|
|
4276
4322
|
for (let parent = path;; parent = dirname(parent)) {
|
|
4277
|
-
assertSafeAncestor(await lstat(parent));
|
|
4323
|
+
assertSafeAncestor(await lstat(parent), parent);
|
|
4278
4324
|
if (parent === dirname(parent))
|
|
4279
4325
|
break;
|
|
4280
4326
|
}
|
|
4281
4327
|
}
|
|
4282
|
-
function assertNativeDirectoryEntry(entry, redirected = false) {
|
|
4283
|
-
if (!entry || !entry.isDirectory() || entry.isSymbolicLink() || entry.uid !== process.getuid?.() || (entry
|
|
4284
|
-
throw new Fault(422, "native_state_permissions",
|
|
4328
|
+
function assertNativeDirectoryEntry(entry, path, redirected = false) {
|
|
4329
|
+
if (!entry || !entry.isDirectory() || entry.isSymbolicLink() || entry.uid !== process.getuid?.() || writableByOthers(entry) || redirected)
|
|
4330
|
+
throw new Fault(422, "native_state_permissions", `Shared native state ${displayPath(path)} must be a real directory owned by you, not writable by other users, with no symbolic link in its path. ${writeFix}; or point HASNA_CLAUDE_STATE_HOME or HASNA_CODEX_STATE_HOME at the real directory.`);
|
|
4285
4331
|
}
|
|
4286
4332
|
async function assertNativeStateDirectory(path) {
|
|
4287
4333
|
const entry = await info(path);
|
|
4288
|
-
assertNativeDirectoryEntry(entry);
|
|
4289
|
-
assertNativeDirectoryEntry(entry, await realpath(path) !== path);
|
|
4334
|
+
assertNativeDirectoryEntry(entry, path);
|
|
4335
|
+
assertNativeDirectoryEntry(entry, path, await realpath(path) !== path);
|
|
4290
4336
|
await assertSafeAncestors(dirname(path));
|
|
4291
4337
|
}
|
|
4292
4338
|
function assertNativeStateDirectorySync(path) {
|
|
@@ -4297,14 +4343,33 @@ function assertNativeStateDirectorySync(path) {
|
|
|
4297
4343
|
if (error.code !== "ENOENT")
|
|
4298
4344
|
throw error;
|
|
4299
4345
|
}
|
|
4300
|
-
assertNativeDirectoryEntry(entry);
|
|
4301
|
-
assertNativeDirectoryEntry(entry, realpathSync(path) !== path);
|
|
4346
|
+
assertNativeDirectoryEntry(entry, path);
|
|
4347
|
+
assertNativeDirectoryEntry(entry, path, realpathSync(path) !== path);
|
|
4302
4348
|
for (let parent = dirname(path);; parent = dirname(parent)) {
|
|
4303
|
-
assertSafeAncestor(lstatSync(parent));
|
|
4349
|
+
assertSafeAncestor(lstatSync(parent), parent);
|
|
4304
4350
|
if (parent === dirname(parent))
|
|
4305
4351
|
break;
|
|
4306
4352
|
}
|
|
4307
4353
|
}
|
|
4354
|
+
async function resolveCorpusLink(path) {
|
|
4355
|
+
const entry = await info(path);
|
|
4356
|
+
if (!entry?.isSymbolicLink())
|
|
4357
|
+
return path;
|
|
4358
|
+
await assertSafeAncestors(dirname(path));
|
|
4359
|
+
if (![0, process.getuid?.()].includes(entry.uid))
|
|
4360
|
+
throw new Fault(422, "native_state_permissions", `Shared native state link ${displayPath(path)} is not owned by you or root. Point HASNA_CLAUDE_STATE_HOME or HASNA_CODEX_STATE_HOME at a real directory you own.`);
|
|
4361
|
+
const target = resolve(dirname(path), await readlink(path));
|
|
4362
|
+
let real;
|
|
4363
|
+
try {
|
|
4364
|
+
real = await realpath(path);
|
|
4365
|
+
} catch {
|
|
4366
|
+
throw new Fault(422, "native_state_permissions", `Shared native state link ${displayPath(path)} points at ${displayPath(target)}, which does not exist or cannot be read.`);
|
|
4367
|
+
}
|
|
4368
|
+
if (real !== target)
|
|
4369
|
+
throw new Fault(422, "native_state_permissions", `Shared native state link ${displayPath(path)} points at ${displayPath(target)} through another symbolic link. Point it directly at the real directory ${displayPath(real)}.`);
|
|
4370
|
+
await assertNativeStateDirectory(real);
|
|
4371
|
+
return real;
|
|
4372
|
+
}
|
|
4308
4373
|
async function ensureNativeStateDirectory(path, create = true) {
|
|
4309
4374
|
if (await info(path))
|
|
4310
4375
|
return assertNativeStateDirectory(path);
|
|
@@ -4382,9 +4447,13 @@ async function resolveNativeState(tool, environment = process.env, options = {})
|
|
|
4382
4447
|
if (primary !== undefined && legacy !== undefined && absolute(primary) !== absolute(legacy))
|
|
4383
4448
|
throw new Fault(409, "native_state_identity_conflict", `The ${marker} and ${legacyMarker} corpus identities disagree. Select one exact shared native state directory before launching.`);
|
|
4384
4449
|
const userHome = absolute(environment.HOME ?? homedir());
|
|
4385
|
-
|
|
4450
|
+
let selected = primary !== undefined ? absolute(primary) : legacy !== undefined ? absolute(legacy) : join(userHome, `.${tool}`);
|
|
4386
4451
|
if (credentialOverlay(selected))
|
|
4387
4452
|
throw new Fault(422, "native_state_overlay", "An authentication profile cannot be the shared native state directory. Select its original native state directory.");
|
|
4453
|
+
const real = primary === undefined && legacy === undefined ? await resolveCorpusLink(selected) : selected;
|
|
4454
|
+
if (real !== selected && credentialOverlay(real))
|
|
4455
|
+
throw new Fault(422, "native_state_overlay", `The shared native state link ${displayPath(selected)} points into an authentication profile. Select its original native state directory.`);
|
|
4456
|
+
selected = real;
|
|
4388
4457
|
await ensureNativeStateDirectory(selected, options.create !== false);
|
|
4389
4458
|
if (tool === "claude")
|
|
4390
4459
|
return { tool, home: selected, marker };
|
|
@@ -5107,7 +5176,7 @@ async function applyDesktopSelection(library, config, label2, checkpoint) {
|
|
|
5107
5176
|
import { execFile } from "node:child_process";
|
|
5108
5177
|
import { access, stat } from "node:fs/promises";
|
|
5109
5178
|
import { constants as constants3 } from "node:fs";
|
|
5110
|
-
import { homedir as homedir2, userInfo } from "node:os";
|
|
5179
|
+
import { homedir as homedir2, userInfo as userInfo2 } from "node:os";
|
|
5111
5180
|
import { isAbsolute as isAbsolute2, join as join3 } from "node:path";
|
|
5112
5181
|
import { promisify } from "node:util";
|
|
5113
5182
|
var execute = promisify(execFile);
|
|
@@ -5169,7 +5238,7 @@ function validateClaudeDesktopVersion(app) {
|
|
|
5169
5238
|
throw new Fault(422, "desktop_version", "Claude desktop 1.52386.0 or newer is required for the gateway adapter.");
|
|
5170
5239
|
}
|
|
5171
5240
|
async function assertClaudeDesktopAvailable(userData) {
|
|
5172
|
-
for (const path of [join3("/Library/Managed Preferences",
|
|
5241
|
+
for (const path of [join3("/Library/Managed Preferences", userInfo2().username, "com.anthropic.claudefordesktop.plist"), "/Library/Managed Preferences/com.anthropic.claudefordesktop.plist"])
|
|
5173
5242
|
if (await access(path).then(() => true, () => false))
|
|
5174
5243
|
throw new Fault(409, "desktop_managed", "Claude has managed preferences; Switcher will not override them.");
|
|
5175
5244
|
let openFiles;
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
/** An env key that routes or authenticates inference, or may carry a credential. */
|
|
2
|
+
export declare function routingOrCredentialEnvironmentKey(key: string): boolean;
|
|
1
3
|
/** Seed a new private settings scope once, preserving native edits on later
|
|
2
|
-
* launches. No symlink, overwrite, credential migration or precedence change.
|
|
3
|
-
|
|
4
|
+
* launches. No symlink, overwrite, credential migration or precedence change.
|
|
5
|
+
* An explicit CLAUDE_CONFIG_DIR stays the settings source. Otherwise the
|
|
6
|
+
* source is the corpus resolveNativeState selected (its real path), so a
|
|
7
|
+
* ~/.claude symlink is never read through. */
|
|
8
|
+
export declare function prepareClaudeUserSettings(overlayHome: string, environment?: NodeJS.ProcessEnv, corpusHome?: string): Promise<string[]>;
|
package/dist/cli/index.js
CHANGED
|
@@ -514,7 +514,7 @@ function canonicalPolicyJSON(value) {
|
|
|
514
514
|
return JSON.stringify(value, (_key, item) => item && typeof item === "object" && !Array.isArray(item) ? Object.fromEntries(Object.entries(item).sort(([a], [b]) => a.localeCompare(b))) : item);
|
|
515
515
|
}
|
|
516
516
|
// package.json
|
|
517
|
-
var version = "0.2.
|
|
517
|
+
var version = "0.2.16";
|
|
518
518
|
|
|
519
519
|
// src/version.ts
|
|
520
520
|
var VERSION = version;
|
|
@@ -2570,7 +2570,7 @@ var openapi_default = {
|
|
|
2570
2570
|
openapi: "3.0.3",
|
|
2571
2571
|
info: {
|
|
2572
2572
|
title: "Switcher API",
|
|
2573
|
-
version: "0.2.
|
|
2573
|
+
version: "0.2.16",
|
|
2574
2574
|
description: "Authenticated provider/profile/catalog control plane. Launches run locally; the API never returns provider credentials."
|
|
2575
2575
|
},
|
|
2576
2576
|
security: [
|
|
@@ -8336,6 +8336,31 @@ var MAX_REQUEST_BODY_BYTES = 64 * 1024 * 1024;
|
|
|
8336
8336
|
var REQUEST_BYTES_PER_CONTEXT_TOKEN = 16;
|
|
8337
8337
|
var CLOSING_MESSAGE = "Switcher gateway: this launch is shutting down. Start a new session with `switcher launch`.";
|
|
8338
8338
|
var PROVIDER_FIX = "Check the provider's status and your network, then retry.";
|
|
8339
|
+
var EXPLAINED_UPSTREAM_STATUSES = new Set([400, 413, 422]);
|
|
8340
|
+
var LARGE_TOOL_COUNT = 128;
|
|
8341
|
+
var LARGE_REQUEST_BYTES = 256 * 1024;
|
|
8342
|
+
function toolDefinitionCount(body) {
|
|
8343
|
+
const record2 = (value) => value && typeof value === "object" && !Array.isArray(value) ? value : undefined;
|
|
8344
|
+
const count = (value) => {
|
|
8345
|
+
if (!value)
|
|
8346
|
+
return 0;
|
|
8347
|
+
let total = Array.isArray(value.functions) ? value.functions.length : 0;
|
|
8348
|
+
for (const tool of Array.isArray(value.tools) ? value.tools : []) {
|
|
8349
|
+
const declarations = record2(tool)?.functionDeclarations ?? record2(tool)?.function_declarations;
|
|
8350
|
+
total += Array.isArray(declarations) ? declarations.length : 1;
|
|
8351
|
+
}
|
|
8352
|
+
return total;
|
|
8353
|
+
};
|
|
8354
|
+
const top = record2(body);
|
|
8355
|
+
return count(top) + count(record2(top?.generateContentRequest));
|
|
8356
|
+
}
|
|
8357
|
+
function upstreamRejectionMessage(status, providerId, sent) {
|
|
8358
|
+
const provider = idSchema.safeParse(providerId).success ? `the provider ${providerId}` : "the provider";
|
|
8359
|
+
const message = `Switcher inference gateway: ${provider} rejected the request with HTTP ${status} (upstream_http_${status}). Switcher sent ${sent.tools} tool definition${sent.tools === 1 ? "" : "s"} in a ${Math.ceil(sent.bytes / 1024)} KB request.`;
|
|
8360
|
+
if (sent.tools <= LARGE_TOOL_COUNT && sent.bytes <= LARGE_REQUEST_BYTES)
|
|
8361
|
+
return message;
|
|
8362
|
+
return `${message} Some providers reject large tool sets or large requests. Start a new session instead of resuming this one, or reduce the MCP servers enabled for this harness.`;
|
|
8363
|
+
}
|
|
8339
8364
|
function requestBodyLimit(models, policy) {
|
|
8340
8365
|
const allowed = new Set(policy.allowedModels);
|
|
8341
8366
|
const contextWindow = Math.max(0, ...models.filter((model) => allowed.has(model.id)).map((model) => Number.isSafeInteger(model.contextWindow) && model.contextWindow > 0 ? model.contextWindow : 0));
|
|
@@ -8480,6 +8505,7 @@ function createInferenceHandler(input, timing = {}, options = {}) {
|
|
|
8480
8505
|
headers["anthropic-beta"] = request.headers.get("anthropic-beta");
|
|
8481
8506
|
}
|
|
8482
8507
|
const candidates = [resolved, ...policy.fallbacks[resolved] ?? []];
|
|
8508
|
+
let sent = { tools: 0, bytes: 0 };
|
|
8483
8509
|
try {
|
|
8484
8510
|
if (candidates.some((model) => !known.has(model) || !policy.allowedModels.includes(model)))
|
|
8485
8511
|
throw new Error("invalid_fallback_policy");
|
|
@@ -8514,8 +8540,10 @@ function createInferenceHandler(input, timing = {}, options = {}) {
|
|
|
8514
8540
|
delete upstreamHeaders["anthropic-beta"];
|
|
8515
8541
|
Object.assign(upstreamHeaders, translated.auth);
|
|
8516
8542
|
}
|
|
8543
|
+
const sentBody = translated?.body ?? outgoing, serialized = JSON.stringify(sentBody);
|
|
8544
|
+
sent = { tools: toolDefinitionCount(sentBody), bytes: Buffer.byteLength(serialized) };
|
|
8517
8545
|
try {
|
|
8518
|
-
response = await activity.run(() => fetch(endpoint(input.baseUrl) + path, { method: "POST", headers: upstreamHeaders, body:
|
|
8546
|
+
response = await activity.run(() => fetch(endpoint(input.baseUrl) + path, { method: "POST", headers: upstreamHeaders, body: serialized, redirect: "manual", ...activity.fetchOptions }));
|
|
8519
8547
|
} catch {
|
|
8520
8548
|
current.reason = activity.timedOut() ? "provider_idle_timeout" : signal.aborted ? "request_cancelled" : "network_error";
|
|
8521
8549
|
throw new Error("provider_request_failed");
|
|
@@ -8546,7 +8574,7 @@ function createInferenceHandler(input, timing = {}, options = {}) {
|
|
|
8546
8574
|
return Response.json({ type: "error", error: { type: "invalid_request_error", code: "context_length_exceeded", message: "prompt is too long: the provider context window was exceeded. Compact the conversation or start a new session." } }, { status: 400 });
|
|
8547
8575
|
if (paymentRequired)
|
|
8548
8576
|
return fail(402, "provider_payment_required", "The selected provider rejected this request for billing or credit limits (HTTP 402). Check the account balance, API-key spending limit, and requested output-token budget before retrying.");
|
|
8549
|
-
const rejected = fail(response.status >= 300 && response.status < 400 ? 502 : response.status, `upstream_http_${response.status}
|
|
8577
|
+
const rejected = fail(response.status >= 300 && response.status < 400 ? 502 : response.status, `upstream_http_${response.status}`, EXPLAINED_UPSTREAM_STATUSES.has(response.status) ? upstreamRejectionMessage(response.status, input.providerId, sent) : undefined);
|
|
8550
8578
|
const retryAfter = response.headers.get("retry-after");
|
|
8551
8579
|
if ((response.status === 429 || response.status === 503) && retryAfter && retryAfter.length <= 128 && (/^\d+$/.test(retryAfter) || Number.isFinite(Date.parse(retryAfter))))
|
|
8552
8580
|
rejected.headers.set("retry-after", retryAfter);
|
|
@@ -11411,7 +11439,7 @@ exec "$SWITCHER_ORI_NATIVE_EXECUTABLE" ${prepared.args.map(quote2).join(" ")}
|
|
|
11411
11439
|
}
|
|
11412
11440
|
|
|
11413
11441
|
// src/launcher.ts
|
|
11414
|
-
import { mkdir as mkdir14, mkdtemp, rm as rm6, writeFile as writeFile18 } from "fs/promises";
|
|
11442
|
+
import { mkdir as mkdir14, mkdtemp, realpath as realpath8, rm as rm6, writeFile as writeFile18 } from "fs/promises";
|
|
11415
11443
|
import { join as join24, resolve as resolve14 } from "path";
|
|
11416
11444
|
|
|
11417
11445
|
// src/provider-credential-onboarding.ts
|
|
@@ -13079,7 +13107,8 @@ async function openDesktopLease(path, readOnly2 = false) {
|
|
|
13079
13107
|
// src/native-state.ts
|
|
13080
13108
|
import { lstat as lstat8, mkdir as mkdir11, open as open5, opendir, readlink, realpath as realpath6, rmdir, symlink as symlink4, unlink as unlink2 } from "fs/promises";
|
|
13081
13109
|
import { constants as constants8, lstatSync as lstatSync2, realpathSync } from "fs";
|
|
13082
|
-
import {
|
|
13110
|
+
import { execFileSync as execFileSync3 } from "child_process";
|
|
13111
|
+
import { homedir as homedir9, userInfo as userInfo3 } from "os";
|
|
13083
13112
|
import { dirname as dirname8, isAbsolute as isAbsolute16, join as join17, relative as relative5, resolve as resolve10 } from "path";
|
|
13084
13113
|
function nativeStateRequested(tool, environment = process.env, explicit) {
|
|
13085
13114
|
if (explicit !== undefined)
|
|
@@ -13131,31 +13160,95 @@ function absolute(value) {
|
|
|
13131
13160
|
throw new Fault(422, "native_state_path", "The shared native state directory must be an absolute path.");
|
|
13132
13161
|
return resolve10(value);
|
|
13133
13162
|
}
|
|
13163
|
+
function displayPath(path) {
|
|
13164
|
+
const value = JSON.stringify(path).replace(/[\u007f-\u009f\u061c\u200e\u200f\u2028-\u202e\u2066-\u2069]/g, (character) => `\\u${character.charCodeAt(0).toString(16).padStart(4, "0")}`);
|
|
13165
|
+
return value.length > 768 ? `${value.slice(0, 384)}...${value.slice(-381)}` : value;
|
|
13166
|
+
}
|
|
13167
|
+
function isUserPrivateGroup(gid, user, group, passwd) {
|
|
13168
|
+
if (gid === 0 || user.uid === 0 || gid !== user.gid)
|
|
13169
|
+
return false;
|
|
13170
|
+
const groups = group.split(`
|
|
13171
|
+
`).filter(Boolean);
|
|
13172
|
+
if (groups.length !== 1)
|
|
13173
|
+
return false;
|
|
13174
|
+
const [groupName, , groupId, members = "", ...extra] = groups[0].split(":");
|
|
13175
|
+
if (extra.length || groupName !== user.name || Number(groupId) !== gid || members.split(",").some((member) => member !== "" && member !== user.name))
|
|
13176
|
+
return false;
|
|
13177
|
+
const accounts = passwd.split(`
|
|
13178
|
+
`).filter(Boolean).map((line) => line.split(":"));
|
|
13179
|
+
if (accounts.some((fields) => fields.length < 4 || !/^\d+$/.test(fields[3] ?? "")))
|
|
13180
|
+
return false;
|
|
13181
|
+
const primary = accounts.filter((fields) => Number(fields[3]) === gid);
|
|
13182
|
+
return primary.length === 1 && primary[0][0] === user.name && Number(primary[0][2]) === user.uid;
|
|
13183
|
+
}
|
|
13184
|
+
function probeUserPrivateGroup(gid) {
|
|
13185
|
+
if (process.platform !== "linux")
|
|
13186
|
+
return false;
|
|
13187
|
+
try {
|
|
13188
|
+
const run = (args) => execFileSync3("getent", args, { encoding: "utf8", timeout: 5000, stdio: ["ignore", "pipe", "ignore"] });
|
|
13189
|
+
return isUserPrivateGroup(gid, { uid: process.getuid(), gid: process.getgid(), name: userInfo3().username }, run(["group", String(gid)]), run(["passwd"]));
|
|
13190
|
+
} catch {
|
|
13191
|
+
return false;
|
|
13192
|
+
}
|
|
13193
|
+
}
|
|
13194
|
+
var privateGroupProbe = probeUserPrivateGroup;
|
|
13195
|
+
var privateGroupAnswers = new Map;
|
|
13196
|
+
function userPrivateGroup(gid) {
|
|
13197
|
+
let answer = privateGroupAnswers.get(gid);
|
|
13198
|
+
if (answer === undefined) {
|
|
13199
|
+
answer = privateGroupProbe(gid);
|
|
13200
|
+
privateGroupAnswers.set(gid, answer);
|
|
13201
|
+
}
|
|
13202
|
+
return answer;
|
|
13203
|
+
}
|
|
13204
|
+
function writableByOthers(entry) {
|
|
13205
|
+
return (entry.mode & 2) !== 0 || (entry.mode & 16) !== 0 && !userPrivateGroup(entry.gid);
|
|
13206
|
+
}
|
|
13207
|
+
var writeFix = "Remove group and other write permission (chmod go-w), or on Linux keep group write only for your own private group";
|
|
13134
13208
|
function credentialOverlay(path) {
|
|
13135
13209
|
return /(?:^|\/)subscriptions\/profiles\//.test(path) || /(?:^|\/)switcher\/state\/(?:desktop|desktop-claude|launch-[^/]+)\//.test(path);
|
|
13136
13210
|
}
|
|
13137
|
-
function assertSafeAncestor(ancestor) {
|
|
13211
|
+
function assertSafeAncestor(ancestor, path) {
|
|
13138
13212
|
const stickyRoot = ancestor.uid === 0 && (ancestor.mode & 512) !== 0;
|
|
13139
|
-
if (!ancestor.isDirectory() || ancestor.isSymbolicLink() || ![0, process.getuid?.()].includes(ancestor.uid) || (ancestor
|
|
13140
|
-
throw new Fault(422, "native_state_permissions",
|
|
13213
|
+
if (!ancestor.isDirectory() || ancestor.isSymbolicLink() || ![0, process.getuid?.()].includes(ancestor.uid) || writableByOthers(ancestor) && !stickyRoot)
|
|
13214
|
+
throw new Fault(422, "native_state_permissions", `Shared native state has an unsafe ancestor directory ${displayPath(path)}. Each ancestor must be a real directory owned by you or root and not writable by other users. ${writeFix}.`);
|
|
13141
13215
|
}
|
|
13142
13216
|
async function assertSafeAncestors(path) {
|
|
13143
13217
|
for (let parent = path;; parent = dirname8(parent)) {
|
|
13144
|
-
assertSafeAncestor(await lstat8(parent));
|
|
13218
|
+
assertSafeAncestor(await lstat8(parent), parent);
|
|
13145
13219
|
if (parent === dirname8(parent))
|
|
13146
13220
|
break;
|
|
13147
13221
|
}
|
|
13148
13222
|
}
|
|
13149
|
-
function assertNativeDirectoryEntry(entry, redirected = false) {
|
|
13150
|
-
if (!entry || !entry.isDirectory() || entry.isSymbolicLink() || entry.uid !== process.getuid?.() || (entry
|
|
13151
|
-
throw new Fault(422, "native_state_permissions",
|
|
13223
|
+
function assertNativeDirectoryEntry(entry, path, redirected = false) {
|
|
13224
|
+
if (!entry || !entry.isDirectory() || entry.isSymbolicLink() || entry.uid !== process.getuid?.() || writableByOthers(entry) || redirected)
|
|
13225
|
+
throw new Fault(422, "native_state_permissions", `Shared native state ${displayPath(path)} must be a real directory owned by you, not writable by other users, with no symbolic link in its path. ${writeFix}; or point HASNA_CLAUDE_STATE_HOME or HASNA_CODEX_STATE_HOME at the real directory.`);
|
|
13152
13226
|
}
|
|
13153
13227
|
async function assertNativeStateDirectory(path) {
|
|
13154
13228
|
const entry = await info(path);
|
|
13155
|
-
assertNativeDirectoryEntry(entry);
|
|
13156
|
-
assertNativeDirectoryEntry(entry, await realpath6(path) !== path);
|
|
13229
|
+
assertNativeDirectoryEntry(entry, path);
|
|
13230
|
+
assertNativeDirectoryEntry(entry, path, await realpath6(path) !== path);
|
|
13157
13231
|
await assertSafeAncestors(dirname8(path));
|
|
13158
13232
|
}
|
|
13233
|
+
async function resolveCorpusLink(path) {
|
|
13234
|
+
const entry = await info(path);
|
|
13235
|
+
if (!entry?.isSymbolicLink())
|
|
13236
|
+
return path;
|
|
13237
|
+
await assertSafeAncestors(dirname8(path));
|
|
13238
|
+
if (![0, process.getuid?.()].includes(entry.uid))
|
|
13239
|
+
throw new Fault(422, "native_state_permissions", `Shared native state link ${displayPath(path)} is not owned by you or root. Point HASNA_CLAUDE_STATE_HOME or HASNA_CODEX_STATE_HOME at a real directory you own.`);
|
|
13240
|
+
const target = resolve10(dirname8(path), await readlink(path));
|
|
13241
|
+
let real;
|
|
13242
|
+
try {
|
|
13243
|
+
real = await realpath6(path);
|
|
13244
|
+
} catch {
|
|
13245
|
+
throw new Fault(422, "native_state_permissions", `Shared native state link ${displayPath(path)} points at ${displayPath(target)}, which does not exist or cannot be read.`);
|
|
13246
|
+
}
|
|
13247
|
+
if (real !== target)
|
|
13248
|
+
throw new Fault(422, "native_state_permissions", `Shared native state link ${displayPath(path)} points at ${displayPath(target)} through another symbolic link. Point it directly at the real directory ${displayPath(real)}.`);
|
|
13249
|
+
await assertNativeStateDirectory(real);
|
|
13250
|
+
return real;
|
|
13251
|
+
}
|
|
13159
13252
|
async function ensureNativeStateDirectory(path, create = true) {
|
|
13160
13253
|
if (await info(path))
|
|
13161
13254
|
return assertNativeStateDirectory(path);
|
|
@@ -13227,19 +13320,22 @@ async function assertShareableTree(path, budget = { entries: 0 }, depth = 0) {
|
|
|
13227
13320
|
if (depth === 0)
|
|
13228
13321
|
await assertNativeStateDirectory(path);
|
|
13229
13322
|
for await (const child of await opendir(path)) {
|
|
13230
|
-
|
|
13231
|
-
|
|
13232
|
-
|
|
13233
|
-
if (
|
|
13234
|
-
throw new Fault(422, "native_state_entry",
|
|
13323
|
+
const nested = join17(path, child.name);
|
|
13324
|
+
if (++budget.entries > 1e5)
|
|
13325
|
+
throw new Fault(422, "native_state_inventory_limit", `The shared native corpus exceeds the safe projection inventory limit of 100,000 entries at ${displayPath(nested)}.`);
|
|
13326
|
+
if (child.isSymbolicLink())
|
|
13327
|
+
throw new Fault(422, "native_state_entry", `The shared native state entry ${displayPath(nested)} is a symbolic link. Shared entries must be regular files and directories.`);
|
|
13328
|
+
const entry = await lstat8(nested);
|
|
13329
|
+
if (entry.uid !== process.getuid?.() || writableByOthers(entry))
|
|
13330
|
+
throw new Fault(422, "native_state_entry", `The shared native state entry ${displayPath(nested)} is not owned by you or is writable by other users. ${writeFix}.`);
|
|
13235
13331
|
if (child.isDirectory()) {
|
|
13236
13332
|
if (!entry.isDirectory())
|
|
13237
|
-
throw new Fault(422, "native_state_entry",
|
|
13333
|
+
throw new Fault(422, "native_state_entry", `The shared native state directory ${displayPath(nested)} changed during inspection.`);
|
|
13238
13334
|
await assertShareableTree(nested, budget, depth + 1);
|
|
13239
13335
|
continue;
|
|
13240
13336
|
}
|
|
13241
13337
|
if (!child.isFile() || !entry.isFile() || entry.nlink !== 1)
|
|
13242
|
-
throw new Fault(422, "native_state_entry",
|
|
13338
|
+
throw new Fault(422, "native_state_entry", `The shared native state entry ${displayPath(nested)} is not a regular file with a single link. Shared entries must be regular files and directories without hardlinks.`);
|
|
13243
13339
|
}
|
|
13244
13340
|
}
|
|
13245
13341
|
async function readCodexStateConfig(home) {
|
|
@@ -13320,9 +13416,13 @@ async function resolveNativeState(tool, environment = process.env, options = {})
|
|
|
13320
13416
|
if (primary !== undefined && legacy !== undefined && absolute(primary) !== absolute(legacy))
|
|
13321
13417
|
throw new Fault(409, "native_state_identity_conflict", `The ${marker} and ${legacyMarker} corpus identities disagree. Select one exact shared native state directory before launching.`);
|
|
13322
13418
|
const userHome = absolute(environment.HOME ?? homedir9());
|
|
13323
|
-
|
|
13419
|
+
let selected = primary !== undefined ? absolute(primary) : legacy !== undefined ? absolute(legacy) : join17(userHome, `.${tool}`);
|
|
13324
13420
|
if (credentialOverlay(selected))
|
|
13325
13421
|
throw new Fault(422, "native_state_overlay", "An authentication profile cannot be the shared native state directory. Select its original native state directory.");
|
|
13422
|
+
const real = primary === undefined && legacy === undefined ? await resolveCorpusLink(selected) : selected;
|
|
13423
|
+
if (real !== selected && credentialOverlay(real))
|
|
13424
|
+
throw new Fault(422, "native_state_overlay", `The shared native state link ${displayPath(selected)} points into an authentication profile. Select its original native state directory.`);
|
|
13425
|
+
selected = real;
|
|
13326
13426
|
await ensureNativeStateDirectory(selected, options.create !== false);
|
|
13327
13427
|
if (tool === "claude")
|
|
13328
13428
|
return { tool, home: selected, marker };
|
|
@@ -13401,10 +13501,7 @@ async function legacyNativeStateWarnings(root, state) {
|
|
|
13401
13501
|
}
|
|
13402
13502
|
}
|
|
13403
13503
|
}
|
|
13404
|
-
const display =
|
|
13405
|
-
const value = JSON.stringify(path).replace(/[\u007f-\u009f\u061c\u200e\u200f\u2028-\u202e\u2066-\u2069]/g, (character) => `\\u${character.charCodeAt(0).toString(16).padStart(4, "0")}`);
|
|
13406
|
-
return value.length > 768 ? `${value.slice(0, 384)}...${value.slice(-381)}` : value;
|
|
13407
|
-
};
|
|
13504
|
+
const display = displayPath;
|
|
13408
13505
|
const warnings = pending.slice(0, 10).map((home) => `Legacy native state is preserved at ${display(home)}; migration is pending. Inspect with switcher state import ${state.tool} --from ${display(home)}. A copied snapshot does not retire the original or migrate its SQLite/index metadata.`);
|
|
13409
13506
|
if (pending.length > warnings.length)
|
|
13410
13507
|
warnings.push(`${pending.length - warnings.length} additional legacy ${state.tool} state directories are pending migration; inspect the Switcher state root before launch.`);
|
|
@@ -13438,12 +13535,12 @@ async function projectNativeStateUnlocked(state, overlayHome) {
|
|
|
13438
13535
|
await ensureNativeStateDirectory(dirname8(target), false);
|
|
13439
13536
|
await ensureNativeStateDirectory(dirname8(destination), false);
|
|
13440
13537
|
const source = await info(target), existing = await info(destination);
|
|
13441
|
-
if (source && (source.isSymbolicLink() || source.uid !== process.getuid?.() || (source
|
|
13442
|
-
throw new Fault(422, "native_state_entry",
|
|
13538
|
+
if (source && (source.isSymbolicLink() || source.uid !== process.getuid?.() || writableByOthers(source) || source.isFile() && source.nlink !== 1 || (entry.kind === "directory" ? !source.isDirectory() : !source.isFile())))
|
|
13539
|
+
throw new Fault(422, "native_state_entry", `The shared native state entry ${displayPath(target)} must be a ${entry.kind === "directory" ? "real directory" : "regular file with a single link"} owned by you and not writable by other users. ${writeFix}.`);
|
|
13443
13540
|
if (source?.isDirectory())
|
|
13444
13541
|
await assertShareableTree(target);
|
|
13445
13542
|
if (existing && (!existing.isSymbolicLink() || resolve10(dirname8(destination), await readlink(destination)) !== target))
|
|
13446
|
-
throw new Fault(409, "native_state_migration_required",
|
|
13543
|
+
throw new Fault(409, "native_state_migration_required", `This launch profile already contains native state at ${displayPath(destination)}, which is not a link to ${displayPath(target)}. Preserve and migrate its noncredential state before linking the shared corpus.`);
|
|
13447
13544
|
}
|
|
13448
13545
|
const createdLinks = [];
|
|
13449
13546
|
const createdFiles = [], createdDirectories = [];
|
|
@@ -13956,10 +14053,28 @@ var preferences = new Set([
|
|
|
13956
14053
|
"showTurnDuration",
|
|
13957
14054
|
"showClearContextOnPlanAccept",
|
|
13958
14055
|
"showCompactionHistory",
|
|
13959
|
-
"teammateMode"
|
|
14056
|
+
"teammateMode",
|
|
14057
|
+
"hooks",
|
|
14058
|
+
"disableAllHooks",
|
|
14059
|
+
"enabledPlugins",
|
|
14060
|
+
"pluginConfigs",
|
|
14061
|
+
"extraKnownMarketplaces",
|
|
14062
|
+
"statusLine",
|
|
14063
|
+
"theme",
|
|
14064
|
+
"tui",
|
|
14065
|
+
"verbose",
|
|
14066
|
+
"skipDangerousModePermissionPrompt",
|
|
14067
|
+
"disableBundledSkills",
|
|
14068
|
+
"syncClaudeAiSkills",
|
|
14069
|
+
"autoCompactEnabled",
|
|
14070
|
+
"autoCompactWindow"
|
|
13960
14071
|
]);
|
|
13961
|
-
var routing3 = new Set(["model", "modelPicker", "fallbackModel"]);
|
|
13962
|
-
var
|
|
14072
|
+
var routing3 = new Set(["model", "modelPicker", "fallbackModel", "modelSettings"]);
|
|
14073
|
+
var credentialHelpers = new Set(["apiKeyHelper", "awsAuthRefresh", "awsCredentialExport", "otelHeadersHelper", "forceLoginMethod", "forceLoginOrgUUID"]);
|
|
14074
|
+
function routingOrCredentialEnvironmentKey(key) {
|
|
14075
|
+
return /^(?:ANTHROPIC_|CLAUDE_CODE_USE_|CLAUDE_CODE_OAUTH|AWS_|GOOGLE_|VERTEX_|CLOUD_ML_|AZURE_|OTEL_EXPORTER_OTLP_HEADERS)/i.test(key) || /TOKEN|KEY|SECRET|PASSWORD|CREDENTIAL|AUTH|PROXY/i.test(key);
|
|
14076
|
+
}
|
|
14077
|
+
var invalid4 = (path) => new Fault(422, "claude_user_settings", `Claude user settings ${displayPath(path)} cannot be safely projected. Use a regular JSON file with a single link, owned by you and not writable by other users, with supported preferences and permission policy.`);
|
|
13963
14078
|
async function readSettings(home) {
|
|
13964
14079
|
await ensureNativeStateDirectory(home, false);
|
|
13965
14080
|
const path = join20(home, "settings.json");
|
|
@@ -13970,66 +14085,84 @@ async function readSettings(home) {
|
|
|
13970
14085
|
});
|
|
13971
14086
|
if (!entry)
|
|
13972
14087
|
return;
|
|
13973
|
-
if (!entry.isFile() || entry.isSymbolicLink() || entry.nlink !== 1 || entry.uid !== process.getuid?.() || (entry
|
|
13974
|
-
throw invalid4();
|
|
14088
|
+
if (!entry.isFile() || entry.isSymbolicLink() || entry.nlink !== 1 || entry.uid !== process.getuid?.() || writableByOthers(entry) || entry.size > 1024 * 1024)
|
|
14089
|
+
throw invalid4(path);
|
|
13975
14090
|
const handle = await open6(path, constants9.O_RDONLY | constants9.O_NOFOLLOW);
|
|
13976
14091
|
try {
|
|
13977
14092
|
const opened = await handle.stat();
|
|
13978
14093
|
if (opened.dev !== entry.dev || opened.ino !== entry.ino || opened.nlink !== 1 || opened.size > 1024 * 1024)
|
|
13979
|
-
throw invalid4();
|
|
14094
|
+
throw invalid4(path);
|
|
13980
14095
|
const value = JSON.parse(await handle.readFile("utf8"));
|
|
13981
14096
|
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
13982
|
-
throw invalid4();
|
|
14097
|
+
throw invalid4(path);
|
|
13983
14098
|
return value;
|
|
13984
14099
|
} catch (error) {
|
|
13985
14100
|
if (error instanceof Fault)
|
|
13986
14101
|
throw error;
|
|
13987
|
-
throw invalid4();
|
|
14102
|
+
throw invalid4(path);
|
|
13988
14103
|
} finally {
|
|
13989
14104
|
await handle.close();
|
|
13990
14105
|
}
|
|
13991
14106
|
}
|
|
13992
|
-
function project(settings2, existing) {
|
|
13993
|
-
const result = {};
|
|
14107
|
+
function project(settings2, existing, path) {
|
|
14108
|
+
const result = {}, dropped = [];
|
|
14109
|
+
const unsupported3 = (name, why) => new Fault(422, "claude_settings_unsupported", `Claude user settings ${displayPath(path)} contain ${JSON.stringify(name)}, ${why}. Keep credentials and provider routing in the selected Switcher profile; remove that setting from this file, or launch with CLAUDE_CONFIG_DIR set to a Claude home without it.`);
|
|
13994
14110
|
for (const [key, value] of Object.entries(settings2)) {
|
|
13995
14111
|
if (routing3.has(key)) {
|
|
13996
14112
|
if (existing && key === "fallbackModel")
|
|
13997
|
-
throw new Fault(409, "claude_settings_routing",
|
|
14113
|
+
throw new Fault(409, "claude_settings_routing", `The private Claude settings ${displayPath(path)} select a fallback model. Resolve that conflict with the Switcher profile before launching.`);
|
|
14114
|
+
continue;
|
|
14115
|
+
}
|
|
14116
|
+
if (credentialHelpers.has(key))
|
|
14117
|
+
throw unsupported3(key, "which authenticates or routes requests");
|
|
14118
|
+
if (key === "env") {
|
|
14119
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
14120
|
+
throw unsupported3("env", "which is not an object of string values");
|
|
14121
|
+
for (const [name, item2] of Object.entries(value)) {
|
|
14122
|
+
if (routingOrCredentialEnvironmentKey(name))
|
|
14123
|
+
throw unsupported3(`env.${name}`, "which routes or authenticates requests or may carry a credential");
|
|
14124
|
+
if (typeof item2 !== "string")
|
|
14125
|
+
throw unsupported3(`env.${name}`, "which is not a string");
|
|
14126
|
+
}
|
|
14127
|
+
if (Object.keys(value).length)
|
|
14128
|
+
result[key] = value;
|
|
13998
14129
|
continue;
|
|
13999
14130
|
}
|
|
14000
|
-
if (
|
|
14131
|
+
if (!preferences.has(key)) {
|
|
14132
|
+
dropped.push(key);
|
|
14001
14133
|
continue;
|
|
14002
|
-
|
|
14003
|
-
throw new Fault(422, "claude_settings_unsupported", "Claude user settings contain an unsupported environment, helper or capability setting. Keep credentials and provider routing in the selected profile; resolve this settings projection explicitly before launching.");
|
|
14134
|
+
}
|
|
14004
14135
|
result[key] = value;
|
|
14005
14136
|
}
|
|
14006
|
-
return result;
|
|
14137
|
+
return { settings: result, dropped };
|
|
14007
14138
|
}
|
|
14008
|
-
async function prepareClaudeUserSettings(overlayHome, environment = process.env) {
|
|
14139
|
+
async function prepareClaudeUserSettings(overlayHome, environment = process.env, corpusHome) {
|
|
14009
14140
|
overlayHome = resolve11(overlayHome);
|
|
14141
|
+
const target = join20(overlayHome, "settings.json");
|
|
14010
14142
|
const existing = await readSettings(overlayHome);
|
|
14011
14143
|
if (existing !== undefined) {
|
|
14012
|
-
project(existing, true);
|
|
14013
|
-
return;
|
|
14144
|
+
project(existing, true, target);
|
|
14145
|
+
return [];
|
|
14014
14146
|
}
|
|
14015
|
-
const sourceHome = resolve11(environment.CLAUDE_CONFIG_DIR ?? join20(environment.HOME ?? homedir10(), ".claude"));
|
|
14147
|
+
const sourceHome = resolve11(environment.CLAUDE_CONFIG_DIR ?? corpusHome ?? join20(environment.HOME ?? homedir10(), ".claude"));
|
|
14016
14148
|
if (sourceHome === overlayHome)
|
|
14017
|
-
return;
|
|
14149
|
+
return [];
|
|
14018
14150
|
const source = await readSettings(sourceHome);
|
|
14019
14151
|
if (source === undefined)
|
|
14020
|
-
return;
|
|
14021
|
-
const settings2 = project(source, false);
|
|
14152
|
+
return [];
|
|
14153
|
+
const { settings: settings2, dropped } = project(source, false, join20(sourceHome, "settings.json"));
|
|
14022
14154
|
await ensureNativeStateDirectory(overlayHome);
|
|
14023
14155
|
try {
|
|
14024
|
-
await writeFile16(
|
|
14156
|
+
await writeFile16(target, JSON.stringify(settings2, null, 2) + `
|
|
14025
14157
|
`, { mode: 384, flag: "wx" });
|
|
14026
14158
|
} catch (error) {
|
|
14027
14159
|
if (error.code !== "EEXIST")
|
|
14028
14160
|
throw error;
|
|
14029
14161
|
const concurrent = await readSettings(overlayHome);
|
|
14030
|
-
if (concurrent === undefined || JSON.stringify(project(concurrent, true)) !== JSON.stringify(settings2))
|
|
14031
|
-
throw new Fault(409, "claude_user_settings_changed",
|
|
14162
|
+
if (concurrent === undefined || JSON.stringify(project(concurrent, true, target).settings) !== JSON.stringify(settings2))
|
|
14163
|
+
throw new Fault(409, "claude_user_settings_changed", `The private Claude settings ${displayPath(target)} changed during preparation. Existing settings were preserved; retry after resolving the concurrent launch.`);
|
|
14032
14164
|
}
|
|
14165
|
+
return dropped.length ? [`Claude user settings not copied to this launch's private settings (unsupported keys): ${dropped.map((key) => JSON.stringify(key)).join(", ")}.`] : [];
|
|
14033
14166
|
}
|
|
14034
14167
|
|
|
14035
14168
|
// src/claude-desktop-launch.ts
|
|
@@ -14072,8 +14205,7 @@ async function prepareClaudeDesktopLaunch(input, app, sessionDir, system) {
|
|
|
14072
14205
|
const localConfig = await safeDesktopRead(join21(userData, "claude_desktop_config.json"));
|
|
14073
14206
|
if (localConfig && JSON.parse(localConfig).deploymentMode === "1p")
|
|
14074
14207
|
throw new Fault(409, "desktop_mode", "Claude's third-party profile is set to standard account mode. Select third-party mode in Claude before launching this gateway.");
|
|
14075
|
-
|
|
14076
|
-
await prepareClaudeUserSettings(sessionDir);
|
|
14208
|
+
const settingsWarnings = input.sharedState ? await prepareClaudeUserSettings(sessionDir, process.env, input.sharedState.home) : [];
|
|
14077
14209
|
await privateDirectory(sessionDir);
|
|
14078
14210
|
if (input.sharedState)
|
|
14079
14211
|
await projectNativeState(input.sharedState, sessionDir);
|
|
@@ -14106,7 +14238,7 @@ async function prepareClaudeDesktopLaunch(input, app, sessionDir, system) {
|
|
|
14106
14238
|
await selection.assertCurrent();
|
|
14107
14239
|
},
|
|
14108
14240
|
cleanup,
|
|
14109
|
-
warnings: [`Claude desktop gateway: ${input.providerId ?? "provider"} / ${input.model}. Uses the shared Claude-3p profile, separate from the normal Claude account. Quit this instance before switching providers; keep Switcher running until then. The previous configuration selection is restored on exit. Managed settings and native permissions remain authoritative.`]
|
|
14241
|
+
warnings: [...settingsWarnings, `Claude desktop gateway: ${input.providerId ?? "provider"} / ${input.model}. Uses the shared Claude-3p profile, separate from the normal Claude account. Quit this instance before switching providers; keep Switcher running until then. The previous configuration selection is restored on exit. Managed settings and native permissions remain authoritative.`]
|
|
14110
14242
|
};
|
|
14111
14243
|
} catch (error) {
|
|
14112
14244
|
try {
|
|
@@ -15746,9 +15878,10 @@ async function launch(client, profileId, options = {}) {
|
|
|
15746
15878
|
if (sharedState && !options.desktop && !options.claudeDesktop) {
|
|
15747
15879
|
const variable = sharedState.tool === "codex" ? "CODEX_HOME" : "CLAUDE_CONFIG_DIR";
|
|
15748
15880
|
const configured = process.env[variable] ? resolve14(process.env[variable]) : undefined;
|
|
15749
|
-
|
|
15881
|
+
const configuredCorpus = configured && await realpath8(configured).catch(() => configured) === sharedState.home;
|
|
15882
|
+
nativeHome2 = sharedState.tool === "claude" && (!configured || configured === sharedState.home || configuredCorpus) ? join24(root, "native-claude", profileId) : configured ?? sharedState.home;
|
|
15750
15883
|
if (sharedState.tool === "claude")
|
|
15751
|
-
await prepareClaudeUserSettings(nativeHome2);
|
|
15884
|
+
stateWarnings.push(...await prepareClaudeUserSettings(nativeHome2, configuredCorpus ? { ...process.env, CLAUDE_CONFIG_DIR: undefined } : process.env, sharedState.home));
|
|
15752
15885
|
await privateDirectory(nativeHome2);
|
|
15753
15886
|
await assertNativeInstructionOverlay(sharedState, nativeHome2);
|
|
15754
15887
|
await projectNativeState(sharedState, nativeHome2);
|
package/dist/mcp/index.js
CHANGED
|
@@ -4049,7 +4049,7 @@ function canonicalPolicyJSON(value) {
|
|
|
4049
4049
|
return JSON.stringify(value, (_key, item) => item && typeof item === "object" && !Array.isArray(item) ? Object.fromEntries(Object.entries(item).sort(([a], [b]) => a.localeCompare(b))) : item);
|
|
4050
4050
|
}
|
|
4051
4051
|
// package.json
|
|
4052
|
-
var version = "0.2.
|
|
4052
|
+
var version = "0.2.16";
|
|
4053
4053
|
|
|
4054
4054
|
// src/version.ts
|
|
4055
4055
|
var VERSION = version;
|
|
@@ -7080,7 +7080,7 @@ var openapi_default = {
|
|
|
7080
7080
|
openapi: "3.0.3",
|
|
7081
7081
|
info: {
|
|
7082
7082
|
title: "Switcher API",
|
|
7083
|
-
version: "0.2.
|
|
7083
|
+
version: "0.2.16",
|
|
7084
7084
|
description: "Authenticated provider/profile/catalog control plane. Launches run locally; the API never returns provider credentials."
|
|
7085
7085
|
},
|
|
7086
7086
|
security: [
|
package/dist/native-state.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type Stats } from "node:fs";
|
|
1
2
|
export type SharedNativeTool = "codex" | "claude";
|
|
2
3
|
export type NativeState = {
|
|
3
4
|
tool: SharedNativeTool;
|
|
@@ -14,6 +15,22 @@ type Entry = {
|
|
|
14
15
|
kind: "directory" | "file";
|
|
15
16
|
};
|
|
16
17
|
export declare const NATIVE_STATE_ENTRIES: Record<SharedNativeTool, readonly Entry[]>;
|
|
18
|
+
/** Quote a path for an error message without passing terminal controls through. */
|
|
19
|
+
export declare function displayPath(path: string): string;
|
|
20
|
+
type PrivateGroupProbe = (gid: number) => boolean;
|
|
21
|
+
/** A Linux user-private group (USERGROUPS, umask 002): the user's own primary
|
|
22
|
+
* group, named after the user, with no members other than the user and no
|
|
23
|
+
* other account using it as a primary group. `group` is `getent group GID`
|
|
24
|
+
* output and `passwd` is `getent passwd` output. */
|
|
25
|
+
export declare function isUserPrivateGroup(gid: number, user: {
|
|
26
|
+
uid: number;
|
|
27
|
+
gid: number;
|
|
28
|
+
name: string;
|
|
29
|
+
}, group: string, passwd: string): boolean;
|
|
30
|
+
/** Tests only: replace the user-private-group lookup. Omit the probe to restore it. */
|
|
31
|
+
export declare function setPrivateGroupProbeForTesting(probe?: PrivateGroupProbe): void;
|
|
32
|
+
/** Other-write is always unsafe. Group-write is safe only for the user's private group. */
|
|
33
|
+
export declare function writableByOthers(entry: Stats): boolean;
|
|
17
34
|
export declare function assertNativeStateDirectory(path: string): Promise<void>;
|
|
18
35
|
/** Same directory policy, without yielding during a final launch handoff. */
|
|
19
36
|
export declare function assertNativeStateDirectorySync(path: string): void;
|
package/dist/serve/index.js
CHANGED
|
@@ -68,7 +68,7 @@ function canonicalPolicyJSON(value) {
|
|
|
68
68
|
return JSON.stringify(value, (_key, item) => item && typeof item === "object" && !Array.isArray(item) ? Object.fromEntries(Object.entries(item).sort(([a], [b]) => a.localeCompare(b))) : item);
|
|
69
69
|
}
|
|
70
70
|
// package.json
|
|
71
|
-
var version = "0.2.
|
|
71
|
+
var version = "0.2.16";
|
|
72
72
|
|
|
73
73
|
// src/version.ts
|
|
74
74
|
var VERSION = version;
|
|
@@ -922,7 +922,7 @@ var openapi_default = {
|
|
|
922
922
|
openapi: "3.0.3",
|
|
923
923
|
info: {
|
|
924
924
|
title: "Switcher API",
|
|
925
|
-
version: "0.2.
|
|
925
|
+
version: "0.2.16",
|
|
926
926
|
description: "Authenticated provider/profile/catalog control plane. Launches run locally; the API never returns provider credentials."
|
|
927
927
|
},
|
|
928
928
|
security: [
|
package/openapi.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hasna/switcher",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.16",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Universal provider and model switcher for coding harnesses with an API, SDK and self-hosted storage",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -79,13 +79,16 @@
|
|
|
79
79
|
},
|
|
80
80
|
"dependencies": {
|
|
81
81
|
"@hasna/contracts": "1.3.8",
|
|
82
|
-
"@modelcontextprotocol/sdk": "
|
|
82
|
+
"@modelcontextprotocol/sdk": "1.32.1",
|
|
83
83
|
"jsonc-parser": "3.3.1",
|
|
84
84
|
"yaml": "2.9.0",
|
|
85
85
|
"zod": "3.25.76",
|
|
86
86
|
"@aws-sdk/client-secrets-manager": "3.1127.0",
|
|
87
87
|
"pg": "8.23.0"
|
|
88
88
|
},
|
|
89
|
+
"overrides": {
|
|
90
|
+
"proxy-addr": "2.0.8"
|
|
91
|
+
},
|
|
89
92
|
"repository": {
|
|
90
93
|
"type": "git",
|
|
91
94
|
"url": "https://github.com/hasna/apps.git",
|