@hasna/switcher 0.2.15 → 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.
@@ -20,7 +20,7 @@ import { lstat as lstat4, opendir as opendir2, realpath as realpath2, stat as st
20
20
  import { lstatSync as lstatSync3 } from "node:fs";
21
21
  import { isAbsolute as isAbsolute3, join as join4, relative as relative2, resolve as resolve3 } from "node:path";
22
22
 
23
- // node_modules/zod/v3/external.js
23
+ // ../../node_modules/.bun/zod@3.25.76/node_modules/zod/v3/external.js
24
24
  var exports_external = {};
25
25
  __export(exports_external, {
26
26
  void: () => voidType,
@@ -132,7 +132,7 @@ __export(exports_external, {
132
132
  BRAND: () => BRAND
133
133
  });
134
134
 
135
- // node_modules/zod/v3/helpers/util.js
135
+ // ../../node_modules/.bun/zod@3.25.76/node_modules/zod/v3/helpers/util.js
136
136
  var util;
137
137
  (function(util2) {
138
138
  util2.assertEqual = (_) => {};
@@ -263,7 +263,7 @@ var getParsedType = (data) => {
263
263
  }
264
264
  };
265
265
 
266
- // node_modules/zod/v3/ZodError.js
266
+ // ../../node_modules/.bun/zod@3.25.76/node_modules/zod/v3/ZodError.js
267
267
  var ZodIssueCode = util.arrayToEnum([
268
268
  "invalid_type",
269
269
  "invalid_literal",
@@ -382,7 +382,7 @@ ZodError.create = (issues) => {
382
382
  return error;
383
383
  };
384
384
 
385
- // node_modules/zod/v3/locales/en.js
385
+ // ../../node_modules/.bun/zod@3.25.76/node_modules/zod/v3/locales/en.js
386
386
  var errorMap = (issue, _ctx) => {
387
387
  let message;
388
388
  switch (issue.code) {
@@ -485,7 +485,7 @@ var errorMap = (issue, _ctx) => {
485
485
  };
486
486
  var en_default = errorMap;
487
487
 
488
- // node_modules/zod/v3/errors.js
488
+ // ../../node_modules/.bun/zod@3.25.76/node_modules/zod/v3/errors.js
489
489
  var overrideErrorMap = en_default;
490
490
  function setErrorMap(map) {
491
491
  overrideErrorMap = map;
@@ -493,7 +493,7 @@ function setErrorMap(map) {
493
493
  function getErrorMap() {
494
494
  return overrideErrorMap;
495
495
  }
496
- // node_modules/zod/v3/helpers/parseUtil.js
496
+ // ../../node_modules/.bun/zod@3.25.76/node_modules/zod/v3/helpers/parseUtil.js
497
497
  var makeIssue = (params) => {
498
498
  const { data, path, errorMaps, issueData } = params;
499
499
  const fullPath = [...path, ...issueData.path || []];
@@ -599,14 +599,14 @@ var isAborted = (x) => x.status === "aborted";
599
599
  var isDirty = (x) => x.status === "dirty";
600
600
  var isValid = (x) => x.status === "valid";
601
601
  var isAsync = (x) => typeof Promise !== "undefined" && x instanceof Promise;
602
- // node_modules/zod/v3/helpers/errorUtil.js
602
+ // ../../node_modules/.bun/zod@3.25.76/node_modules/zod/v3/helpers/errorUtil.js
603
603
  var errorUtil;
604
604
  (function(errorUtil2) {
605
605
  errorUtil2.errToObj = (message) => typeof message === "string" ? { message } : message || {};
606
606
  errorUtil2.toString = (message) => typeof message === "string" ? message : message?.message;
607
607
  })(errorUtil || (errorUtil = {}));
608
608
 
609
- // node_modules/zod/v3/types.js
609
+ // ../../node_modules/.bun/zod@3.25.76/node_modules/zod/v3/types.js
610
610
  class ParseInputLazyPath {
611
611
  constructor(parent, value, path, key) {
612
612
  this._cachedPath = [];
@@ -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 { homedir } from "node:os";
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.mode & 18) !== 0 && !stickyRoot)
4273
- throw new Fault(422, "native_state_permissions", "Shared native state has an unsafe ancestor directory.");
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.mode & 18) !== 0 || redirected)
4284
- throw new Fault(422, "native_state_permissions", "Shared native state must be an owned directory without writable or symbolic-link redirection.");
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
- const selected = primary !== undefined ? absolute(primary) : legacy !== undefined ? absolute(legacy) : join(userHome, `.${tool}`);
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", userInfo().username, "com.anthropic.claudefordesktop.plist"), "/Library/Managed Preferences/com.anthropic.claudefordesktop.plist"])
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
- export declare function prepareClaudeUserSettings(overlayHome: string, environment?: NodeJS.ProcessEnv): Promise<void>;
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.15";
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.15",
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: [
@@ -11439,7 +11439,7 @@ exec "$SWITCHER_ORI_NATIVE_EXECUTABLE" ${prepared.args.map(quote2).join(" ")}
11439
11439
  }
11440
11440
 
11441
11441
  // src/launcher.ts
11442
- 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";
11443
11443
  import { join as join24, resolve as resolve14 } from "path";
11444
11444
 
11445
11445
  // src/provider-credential-onboarding.ts
@@ -13107,7 +13107,8 @@ async function openDesktopLease(path, readOnly2 = false) {
13107
13107
  // src/native-state.ts
13108
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";
13109
13109
  import { constants as constants8, lstatSync as lstatSync2, realpathSync } from "fs";
13110
- import { homedir as homedir9 } from "os";
13110
+ import { execFileSync as execFileSync3 } from "child_process";
13111
+ import { homedir as homedir9, userInfo as userInfo3 } from "os";
13111
13112
  import { dirname as dirname8, isAbsolute as isAbsolute16, join as join17, relative as relative5, resolve as resolve10 } from "path";
13112
13113
  function nativeStateRequested(tool, environment = process.env, explicit) {
13113
13114
  if (explicit !== undefined)
@@ -13159,30 +13160,94 @@ function absolute(value) {
13159
13160
  throw new Fault(422, "native_state_path", "The shared native state directory must be an absolute path.");
13160
13161
  return resolve10(value);
13161
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";
13162
13208
  function credentialOverlay(path) {
13163
13209
  return /(?:^|\/)subscriptions\/profiles\//.test(path) || /(?:^|\/)switcher\/state\/(?:desktop|desktop-claude|launch-[^/]+)\//.test(path);
13164
13210
  }
13165
- function assertSafeAncestor(ancestor) {
13211
+ function assertSafeAncestor(ancestor, path) {
13166
13212
  const stickyRoot = ancestor.uid === 0 && (ancestor.mode & 512) !== 0;
13167
- if (!ancestor.isDirectory() || ancestor.isSymbolicLink() || ![0, process.getuid?.()].includes(ancestor.uid) || (ancestor.mode & 18) !== 0 && !stickyRoot)
13168
- throw new Fault(422, "native_state_permissions", "Shared native state has an unsafe ancestor directory.");
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}.`);
13169
13215
  }
13170
13216
  async function assertSafeAncestors(path) {
13171
13217
  for (let parent = path;; parent = dirname8(parent)) {
13172
- assertSafeAncestor(await lstat8(parent));
13218
+ assertSafeAncestor(await lstat8(parent), parent);
13173
13219
  if (parent === dirname8(parent))
13174
13220
  break;
13175
13221
  }
13176
13222
  }
13177
- function assertNativeDirectoryEntry(entry, redirected = false) {
13178
- if (!entry || !entry.isDirectory() || entry.isSymbolicLink() || entry.uid !== process.getuid?.() || (entry.mode & 18) !== 0 || redirected)
13179
- throw new Fault(422, "native_state_permissions", "Shared native state must be an owned directory without writable or symbolic-link redirection.");
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.`);
13180
13226
  }
13181
13227
  async function assertNativeStateDirectory(path) {
13182
13228
  const entry = await info(path);
13183
- assertNativeDirectoryEntry(entry);
13184
- assertNativeDirectoryEntry(entry, await realpath6(path) !== path);
13229
+ assertNativeDirectoryEntry(entry, path);
13230
+ assertNativeDirectoryEntry(entry, path, await realpath6(path) !== path);
13231
+ await assertSafeAncestors(dirname8(path));
13232
+ }
13233
+ async function resolveCorpusLink(path) {
13234
+ const entry = await info(path);
13235
+ if (!entry?.isSymbolicLink())
13236
+ return path;
13185
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;
13186
13251
  }
13187
13252
  async function ensureNativeStateDirectory(path, create = true) {
13188
13253
  if (await info(path))
@@ -13255,19 +13320,22 @@ async function assertShareableTree(path, budget = { entries: 0 }, depth = 0) {
13255
13320
  if (depth === 0)
13256
13321
  await assertNativeStateDirectory(path);
13257
13322
  for await (const child of await opendir(path)) {
13258
- if (++budget.entries > 1e5 || child.isSymbolicLink())
13259
- throw new Fault(422, "native_state_entry", "A shared native state tree contains an unsupported link or exceeds the safe inventory limit.");
13260
- const nested = join17(path, child.name), entry = await lstat8(nested);
13261
- if (entry.uid !== process.getuid?.() || (entry.mode & 18) !== 0)
13262
- throw new Fault(422, "native_state_entry", "A shared native state entry has unsafe ownership or writable permissions.");
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}.`);
13263
13331
  if (child.isDirectory()) {
13264
13332
  if (!entry.isDirectory())
13265
- throw new Fault(422, "native_state_entry", "A shared native state directory changed during inspection.");
13333
+ throw new Fault(422, "native_state_entry", `The shared native state directory ${displayPath(nested)} changed during inspection.`);
13266
13334
  await assertShareableTree(nested, budget, depth + 1);
13267
13335
  continue;
13268
13336
  }
13269
13337
  if (!child.isFile() || !entry.isFile() || entry.nlink !== 1)
13270
- throw new Fault(422, "native_state_entry", "A shared native state tree contains an unsupported file type or hardlink.");
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.`);
13271
13339
  }
13272
13340
  }
13273
13341
  async function readCodexStateConfig(home) {
@@ -13348,9 +13416,13 @@ async function resolveNativeState(tool, environment = process.env, options = {})
13348
13416
  if (primary !== undefined && legacy !== undefined && absolute(primary) !== absolute(legacy))
13349
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.`);
13350
13418
  const userHome = absolute(environment.HOME ?? homedir9());
13351
- const selected = primary !== undefined ? absolute(primary) : legacy !== undefined ? absolute(legacy) : join17(userHome, `.${tool}`);
13419
+ let selected = primary !== undefined ? absolute(primary) : legacy !== undefined ? absolute(legacy) : join17(userHome, `.${tool}`);
13352
13420
  if (credentialOverlay(selected))
13353
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;
13354
13426
  await ensureNativeStateDirectory(selected, options.create !== false);
13355
13427
  if (tool === "claude")
13356
13428
  return { tool, home: selected, marker };
@@ -13429,10 +13501,7 @@ async function legacyNativeStateWarnings(root, state) {
13429
13501
  }
13430
13502
  }
13431
13503
  }
13432
- const display = (path) => {
13433
- 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")}`);
13434
- return value.length > 768 ? `${value.slice(0, 384)}...${value.slice(-381)}` : value;
13435
- };
13504
+ const display = displayPath;
13436
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.`);
13437
13506
  if (pending.length > warnings.length)
13438
13507
  warnings.push(`${pending.length - warnings.length} additional legacy ${state.tool} state directories are pending migration; inspect the Switcher state root before launch.`);
@@ -13466,12 +13535,12 @@ async function projectNativeStateUnlocked(state, overlayHome) {
13466
13535
  await ensureNativeStateDirectory(dirname8(target), false);
13467
13536
  await ensureNativeStateDirectory(dirname8(destination), false);
13468
13537
  const source = await info(target), existing = await info(destination);
13469
- if (source && (source.isSymbolicLink() || source.uid !== process.getuid?.() || (source.mode & 18) !== 0 || source.isFile() && source.nlink !== 1 || (entry.kind === "directory" ? !source.isDirectory() : !source.isFile())))
13470
- throw new Fault(422, "native_state_entry", "A shared native state entry has an unsupported type, owner or permissions.");
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}.`);
13471
13540
  if (source?.isDirectory())
13472
13541
  await assertShareableTree(target);
13473
13542
  if (existing && (!existing.isSymbolicLink() || resolve10(dirname8(destination), await readlink(destination)) !== target))
13474
- throw new Fault(409, "native_state_migration_required", "This launch profile already contains native state. Preserve and migrate its noncredential state before linking the shared corpus.");
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.`);
13475
13544
  }
13476
13545
  const createdLinks = [];
13477
13546
  const createdFiles = [], createdDirectories = [];
@@ -13984,10 +14053,28 @@ var preferences = new Set([
13984
14053
  "showTurnDuration",
13985
14054
  "showClearContextOnPlanAccept",
13986
14055
  "showCompactionHistory",
13987
- "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"
13988
14071
  ]);
13989
- var routing3 = new Set(["model", "modelPicker", "fallbackModel"]);
13990
- var invalid4 = () => new Fault(422, "claude_user_settings", "Claude user settings cannot be safely projected. Use a regular owned JSON settings file with supported preferences and permission policy.");
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.`);
13991
14078
  async function readSettings(home) {
13992
14079
  await ensureNativeStateDirectory(home, false);
13993
14080
  const path = join20(home, "settings.json");
@@ -13998,66 +14085,84 @@ async function readSettings(home) {
13998
14085
  });
13999
14086
  if (!entry)
14000
14087
  return;
14001
- if (!entry.isFile() || entry.isSymbolicLink() || entry.nlink !== 1 || entry.uid !== process.getuid?.() || (entry.mode & 18) !== 0 || entry.size > 1024 * 1024)
14002
- 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);
14003
14090
  const handle = await open6(path, constants9.O_RDONLY | constants9.O_NOFOLLOW);
14004
14091
  try {
14005
14092
  const opened = await handle.stat();
14006
14093
  if (opened.dev !== entry.dev || opened.ino !== entry.ino || opened.nlink !== 1 || opened.size > 1024 * 1024)
14007
- throw invalid4();
14094
+ throw invalid4(path);
14008
14095
  const value = JSON.parse(await handle.readFile("utf8"));
14009
14096
  if (!value || typeof value !== "object" || Array.isArray(value))
14010
- throw invalid4();
14097
+ throw invalid4(path);
14011
14098
  return value;
14012
14099
  } catch (error) {
14013
14100
  if (error instanceof Fault)
14014
14101
  throw error;
14015
- throw invalid4();
14102
+ throw invalid4(path);
14016
14103
  } finally {
14017
14104
  await handle.close();
14018
14105
  }
14019
14106
  }
14020
- function project(settings2, existing) {
14021
- 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.`);
14022
14110
  for (const [key, value] of Object.entries(settings2)) {
14023
14111
  if (routing3.has(key)) {
14024
14112
  if (existing && key === "fallbackModel")
14025
- throw new Fault(409, "claude_settings_routing", "The private Claude settings select a fallback model. Resolve that conflict with the Switcher profile before launching.");
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;
14026
14129
  continue;
14027
14130
  }
14028
- if (key === "env" && value && typeof value === "object" && !Array.isArray(value) && Object.keys(value).length === 0)
14131
+ if (!preferences.has(key)) {
14132
+ dropped.push(key);
14029
14133
  continue;
14030
- if (!preferences.has(key))
14031
- 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
+ }
14032
14135
  result[key] = value;
14033
14136
  }
14034
- return result;
14137
+ return { settings: result, dropped };
14035
14138
  }
14036
- async function prepareClaudeUserSettings(overlayHome, environment = process.env) {
14139
+ async function prepareClaudeUserSettings(overlayHome, environment = process.env, corpusHome) {
14037
14140
  overlayHome = resolve11(overlayHome);
14141
+ const target = join20(overlayHome, "settings.json");
14038
14142
  const existing = await readSettings(overlayHome);
14039
14143
  if (existing !== undefined) {
14040
- project(existing, true);
14041
- return;
14144
+ project(existing, true, target);
14145
+ return [];
14042
14146
  }
14043
- 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"));
14044
14148
  if (sourceHome === overlayHome)
14045
- return;
14149
+ return [];
14046
14150
  const source = await readSettings(sourceHome);
14047
14151
  if (source === undefined)
14048
- return;
14049
- const settings2 = project(source, false);
14152
+ return [];
14153
+ const { settings: settings2, dropped } = project(source, false, join20(sourceHome, "settings.json"));
14050
14154
  await ensureNativeStateDirectory(overlayHome);
14051
14155
  try {
14052
- await writeFile16(join20(overlayHome, "settings.json"), JSON.stringify(settings2, null, 2) + `
14156
+ await writeFile16(target, JSON.stringify(settings2, null, 2) + `
14053
14157
  `, { mode: 384, flag: "wx" });
14054
14158
  } catch (error) {
14055
14159
  if (error.code !== "EEXIST")
14056
14160
  throw error;
14057
14161
  const concurrent = await readSettings(overlayHome);
14058
- if (concurrent === undefined || JSON.stringify(project(concurrent, true)) !== JSON.stringify(settings2))
14059
- throw new Fault(409, "claude_user_settings_changed", "The private Claude settings changed during preparation. Existing settings were preserved; retry after resolving the concurrent launch.");
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.`);
14060
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(", ")}.`] : [];
14061
14166
  }
14062
14167
 
14063
14168
  // src/claude-desktop-launch.ts
@@ -14100,8 +14205,7 @@ async function prepareClaudeDesktopLaunch(input, app, sessionDir, system) {
14100
14205
  const localConfig = await safeDesktopRead(join21(userData, "claude_desktop_config.json"));
14101
14206
  if (localConfig && JSON.parse(localConfig).deploymentMode === "1p")
14102
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.");
14103
- if (input.sharedState)
14104
- await prepareClaudeUserSettings(sessionDir);
14208
+ const settingsWarnings = input.sharedState ? await prepareClaudeUserSettings(sessionDir, process.env, input.sharedState.home) : [];
14105
14209
  await privateDirectory(sessionDir);
14106
14210
  if (input.sharedState)
14107
14211
  await projectNativeState(input.sharedState, sessionDir);
@@ -14134,7 +14238,7 @@ async function prepareClaudeDesktopLaunch(input, app, sessionDir, system) {
14134
14238
  await selection.assertCurrent();
14135
14239
  },
14136
14240
  cleanup,
14137
- 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.`]
14138
14242
  };
14139
14243
  } catch (error) {
14140
14244
  try {
@@ -15774,9 +15878,10 @@ async function launch(client, profileId, options = {}) {
15774
15878
  if (sharedState && !options.desktop && !options.claudeDesktop) {
15775
15879
  const variable = sharedState.tool === "codex" ? "CODEX_HOME" : "CLAUDE_CONFIG_DIR";
15776
15880
  const configured = process.env[variable] ? resolve14(process.env[variable]) : undefined;
15777
- nativeHome2 = sharedState.tool === "claude" && (!configured || configured === sharedState.home) ? join24(root, "native-claude", profileId) : configured ?? sharedState.home;
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;
15778
15883
  if (sharedState.tool === "claude")
15779
- await prepareClaudeUserSettings(nativeHome2);
15884
+ stateWarnings.push(...await prepareClaudeUserSettings(nativeHome2, configuredCorpus ? { ...process.env, CLAUDE_CONFIG_DIR: undefined } : process.env, sharedState.home));
15780
15885
  await privateDirectory(nativeHome2);
15781
15886
  await assertNativeInstructionOverlay(sharedState, nativeHome2);
15782
15887
  await projectNativeState(sharedState, nativeHome2);
package/dist/index.js CHANGED
@@ -13,7 +13,7 @@ var __export = (target, all) => {
13
13
  });
14
14
  };
15
15
 
16
- // node_modules/zod/v3/external.js
16
+ // ../../node_modules/.bun/zod@3.25.76/node_modules/zod/v3/external.js
17
17
  var exports_external = {};
18
18
  __export(exports_external, {
19
19
  void: () => voidType,
@@ -125,7 +125,7 @@ __export(exports_external, {
125
125
  BRAND: () => BRAND
126
126
  });
127
127
 
128
- // node_modules/zod/v3/helpers/util.js
128
+ // ../../node_modules/.bun/zod@3.25.76/node_modules/zod/v3/helpers/util.js
129
129
  var util;
130
130
  (function(util2) {
131
131
  util2.assertEqual = (_) => {};
@@ -256,7 +256,7 @@ var getParsedType = (data) => {
256
256
  }
257
257
  };
258
258
 
259
- // node_modules/zod/v3/ZodError.js
259
+ // ../../node_modules/.bun/zod@3.25.76/node_modules/zod/v3/ZodError.js
260
260
  var ZodIssueCode = util.arrayToEnum([
261
261
  "invalid_type",
262
262
  "invalid_literal",
@@ -375,7 +375,7 @@ ZodError.create = (issues) => {
375
375
  return error;
376
376
  };
377
377
 
378
- // node_modules/zod/v3/locales/en.js
378
+ // ../../node_modules/.bun/zod@3.25.76/node_modules/zod/v3/locales/en.js
379
379
  var errorMap = (issue, _ctx) => {
380
380
  let message;
381
381
  switch (issue.code) {
@@ -478,7 +478,7 @@ var errorMap = (issue, _ctx) => {
478
478
  };
479
479
  var en_default = errorMap;
480
480
 
481
- // node_modules/zod/v3/errors.js
481
+ // ../../node_modules/.bun/zod@3.25.76/node_modules/zod/v3/errors.js
482
482
  var overrideErrorMap = en_default;
483
483
  function setErrorMap(map) {
484
484
  overrideErrorMap = map;
@@ -486,7 +486,7 @@ function setErrorMap(map) {
486
486
  function getErrorMap() {
487
487
  return overrideErrorMap;
488
488
  }
489
- // node_modules/zod/v3/helpers/parseUtil.js
489
+ // ../../node_modules/.bun/zod@3.25.76/node_modules/zod/v3/helpers/parseUtil.js
490
490
  var makeIssue = (params) => {
491
491
  const { data, path, errorMaps, issueData } = params;
492
492
  const fullPath = [...path, ...issueData.path || []];
@@ -592,14 +592,14 @@ var isAborted = (x) => x.status === "aborted";
592
592
  var isDirty = (x) => x.status === "dirty";
593
593
  var isValid = (x) => x.status === "valid";
594
594
  var isAsync = (x) => typeof Promise !== "undefined" && x instanceof Promise;
595
- // node_modules/zod/v3/helpers/errorUtil.js
595
+ // ../../node_modules/.bun/zod@3.25.76/node_modules/zod/v3/helpers/errorUtil.js
596
596
  var errorUtil;
597
597
  (function(errorUtil2) {
598
598
  errorUtil2.errToObj = (message) => typeof message === "string" ? { message } : message || {};
599
599
  errorUtil2.toString = (message) => typeof message === "string" ? message : message?.message;
600
600
  })(errorUtil || (errorUtil = {}));
601
601
 
602
- // node_modules/zod/v3/types.js
602
+ // ../../node_modules/.bun/zod@3.25.76/node_modules/zod/v3/types.js
603
603
  class ParseInputLazyPath {
604
604
  constructor(parent, value, path, key) {
605
605
  this._cachedPath = [];
@@ -4200,7 +4200,7 @@ async function boundedJson(response, maxBytes = MAX_BYTES) {
4200
4200
  }
4201
4201
  }
4202
4202
 
4203
- // node_modules/@hasna/contracts/dist/client/transport.js
4203
+ // ../contracts/dist/client/transport.js
4204
4204
  import { isIP } from "net";
4205
4205
  import { spawnSync } from "child_process";
4206
4206
  import { closeSync as closeSync2, fstatSync as fstatSync2, openSync as openSync2, readFileSync as readFileSync2 } from "fs";
package/dist/mcp/index.js CHANGED
@@ -19,7 +19,7 @@ var __export = (target, all) => {
19
19
  import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
20
20
  import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
21
21
 
22
- // node_modules/zod/v3/external.js
22
+ // ../../node_modules/.bun/zod@3.25.76/node_modules/zod/v3/external.js
23
23
  var exports_external = {};
24
24
  __export(exports_external, {
25
25
  void: () => voidType,
@@ -131,7 +131,7 @@ __export(exports_external, {
131
131
  BRAND: () => BRAND
132
132
  });
133
133
 
134
- // node_modules/zod/v3/helpers/util.js
134
+ // ../../node_modules/.bun/zod@3.25.76/node_modules/zod/v3/helpers/util.js
135
135
  var util;
136
136
  (function(util2) {
137
137
  util2.assertEqual = (_) => {};
@@ -262,7 +262,7 @@ var getParsedType = (data) => {
262
262
  }
263
263
  };
264
264
 
265
- // node_modules/zod/v3/ZodError.js
265
+ // ../../node_modules/.bun/zod@3.25.76/node_modules/zod/v3/ZodError.js
266
266
  var ZodIssueCode = util.arrayToEnum([
267
267
  "invalid_type",
268
268
  "invalid_literal",
@@ -381,7 +381,7 @@ ZodError.create = (issues) => {
381
381
  return error;
382
382
  };
383
383
 
384
- // node_modules/zod/v3/locales/en.js
384
+ // ../../node_modules/.bun/zod@3.25.76/node_modules/zod/v3/locales/en.js
385
385
  var errorMap = (issue, _ctx) => {
386
386
  let message;
387
387
  switch (issue.code) {
@@ -484,7 +484,7 @@ var errorMap = (issue, _ctx) => {
484
484
  };
485
485
  var en_default = errorMap;
486
486
 
487
- // node_modules/zod/v3/errors.js
487
+ // ../../node_modules/.bun/zod@3.25.76/node_modules/zod/v3/errors.js
488
488
  var overrideErrorMap = en_default;
489
489
  function setErrorMap(map) {
490
490
  overrideErrorMap = map;
@@ -492,7 +492,7 @@ function setErrorMap(map) {
492
492
  function getErrorMap() {
493
493
  return overrideErrorMap;
494
494
  }
495
- // node_modules/zod/v3/helpers/parseUtil.js
495
+ // ../../node_modules/.bun/zod@3.25.76/node_modules/zod/v3/helpers/parseUtil.js
496
496
  var makeIssue = (params) => {
497
497
  const { data, path, errorMaps, issueData } = params;
498
498
  const fullPath = [...path, ...issueData.path || []];
@@ -598,14 +598,14 @@ var isAborted = (x) => x.status === "aborted";
598
598
  var isDirty = (x) => x.status === "dirty";
599
599
  var isValid = (x) => x.status === "valid";
600
600
  var isAsync = (x) => typeof Promise !== "undefined" && x instanceof Promise;
601
- // node_modules/zod/v3/helpers/errorUtil.js
601
+ // ../../node_modules/.bun/zod@3.25.76/node_modules/zod/v3/helpers/errorUtil.js
602
602
  var errorUtil;
603
603
  (function(errorUtil2) {
604
604
  errorUtil2.errToObj = (message) => typeof message === "string" ? { message } : message || {};
605
605
  errorUtil2.toString = (message) => typeof message === "string" ? message : message?.message;
606
606
  })(errorUtil || (errorUtil = {}));
607
607
 
608
- // node_modules/zod/v3/types.js
608
+ // ../../node_modules/.bun/zod@3.25.76/node_modules/zod/v3/types.js
609
609
  class ParseInputLazyPath {
610
610
  constructor(parent, value, path, key) {
611
611
  this._cachedPath = [];
@@ -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.15";
4052
+ var version = "0.2.16";
4053
4053
 
4054
4054
  // src/version.ts
4055
4055
  var VERSION = version;
@@ -4243,7 +4243,7 @@ async function boundedJson(response, maxBytes = MAX_BYTES) {
4243
4243
  }
4244
4244
  }
4245
4245
 
4246
- // node_modules/@hasna/contracts/dist/client/transport.js
4246
+ // ../contracts/dist/client/transport.js
4247
4247
  import { isIP } from "net";
4248
4248
  import { spawnSync } from "child_process";
4249
4249
  import { closeSync as closeSync2, fstatSync as fstatSync2, openSync as openSync2, readFileSync as readFileSync2 } from "fs";
@@ -5919,7 +5919,7 @@ import { chmod, mkdir } from "fs/promises";
5919
5919
  import { dirname as dirname2, resolve } from "path";
5920
5920
  import { createHash as createHash2 } from "crypto";
5921
5921
 
5922
- // node_modules/@hasna/contracts/dist/auth/index.js
5922
+ // ../contracts/dist/auth/index.js
5923
5923
  import { createHash, createHmac, randomBytes, timingSafeEqual } from "crypto";
5924
5924
  var MAX_TENANT_ID_LENGTH = 64;
5925
5925
  var TENANT_ID_PATTERN = new RegExp(`^[A-Za-z0-9][A-Za-z0-9._-]{0,${MAX_TENANT_ID_LENGTH - 1}}$`);
@@ -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.15",
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: [
@@ -11693,7 +11693,7 @@ async function openCliRuntime(env = process.env, resolveCredential2) {
11693
11693
  return { client: new SwitcherClient({ baseUrl: service.url, apiKey }), mode: "local", providerEnv, close: service.close };
11694
11694
  }
11695
11695
 
11696
- // node_modules/@hasna/contracts/dist/executable-trust.js
11696
+ // ../contracts/dist/executable-trust.js
11697
11697
  import { constants as constants2 } from "fs";
11698
11698
  import { access as access2, lstat as lstat2, open, readlink, realpath, rename, unlink } from "fs/promises";
11699
11699
  import { dirname as dirname3, isAbsolute as isAbsolute3, join as join5, parse as parse2, sep as sep2 } from "path";
@@ -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/sdk.js CHANGED
@@ -13,7 +13,7 @@ var __export = (target, all) => {
13
13
  });
14
14
  };
15
15
 
16
- // node_modules/zod/v3/external.js
16
+ // ../../node_modules/.bun/zod@3.25.76/node_modules/zod/v3/external.js
17
17
  var exports_external = {};
18
18
  __export(exports_external, {
19
19
  void: () => voidType,
@@ -125,7 +125,7 @@ __export(exports_external, {
125
125
  BRAND: () => BRAND
126
126
  });
127
127
 
128
- // node_modules/zod/v3/helpers/util.js
128
+ // ../../node_modules/.bun/zod@3.25.76/node_modules/zod/v3/helpers/util.js
129
129
  var util;
130
130
  (function(util2) {
131
131
  util2.assertEqual = (_) => {};
@@ -256,7 +256,7 @@ var getParsedType = (data) => {
256
256
  }
257
257
  };
258
258
 
259
- // node_modules/zod/v3/ZodError.js
259
+ // ../../node_modules/.bun/zod@3.25.76/node_modules/zod/v3/ZodError.js
260
260
  var ZodIssueCode = util.arrayToEnum([
261
261
  "invalid_type",
262
262
  "invalid_literal",
@@ -375,7 +375,7 @@ ZodError.create = (issues) => {
375
375
  return error;
376
376
  };
377
377
 
378
- // node_modules/zod/v3/locales/en.js
378
+ // ../../node_modules/.bun/zod@3.25.76/node_modules/zod/v3/locales/en.js
379
379
  var errorMap = (issue, _ctx) => {
380
380
  let message;
381
381
  switch (issue.code) {
@@ -478,7 +478,7 @@ var errorMap = (issue, _ctx) => {
478
478
  };
479
479
  var en_default = errorMap;
480
480
 
481
- // node_modules/zod/v3/errors.js
481
+ // ../../node_modules/.bun/zod@3.25.76/node_modules/zod/v3/errors.js
482
482
  var overrideErrorMap = en_default;
483
483
  function setErrorMap(map) {
484
484
  overrideErrorMap = map;
@@ -486,7 +486,7 @@ function setErrorMap(map) {
486
486
  function getErrorMap() {
487
487
  return overrideErrorMap;
488
488
  }
489
- // node_modules/zod/v3/helpers/parseUtil.js
489
+ // ../../node_modules/.bun/zod@3.25.76/node_modules/zod/v3/helpers/parseUtil.js
490
490
  var makeIssue = (params) => {
491
491
  const { data, path, errorMaps, issueData } = params;
492
492
  const fullPath = [...path, ...issueData.path || []];
@@ -592,14 +592,14 @@ var isAborted = (x) => x.status === "aborted";
592
592
  var isDirty = (x) => x.status === "dirty";
593
593
  var isValid = (x) => x.status === "valid";
594
594
  var isAsync = (x) => typeof Promise !== "undefined" && x instanceof Promise;
595
- // node_modules/zod/v3/helpers/errorUtil.js
595
+ // ../../node_modules/.bun/zod@3.25.76/node_modules/zod/v3/helpers/errorUtil.js
596
596
  var errorUtil;
597
597
  (function(errorUtil2) {
598
598
  errorUtil2.errToObj = (message) => typeof message === "string" ? { message } : message || {};
599
599
  errorUtil2.toString = (message) => typeof message === "string" ? message : message?.message;
600
600
  })(errorUtil || (errorUtil = {}));
601
601
 
602
- // node_modules/zod/v3/types.js
602
+ // ../../node_modules/.bun/zod@3.25.76/node_modules/zod/v3/types.js
603
603
  class ParseInputLazyPath {
604
604
  constructor(parent, value, path, key) {
605
605
  this._cachedPath = [];
@@ -4200,7 +4200,7 @@ async function boundedJson(response, maxBytes = MAX_BYTES) {
4200
4200
  }
4201
4201
  }
4202
4202
 
4203
- // node_modules/@hasna/contracts/dist/client/transport.js
4203
+ // ../contracts/dist/client/transport.js
4204
4204
  import { isIP } from "net";
4205
4205
  import { spawnSync } from "child_process";
4206
4206
  import { closeSync as closeSync2, fstatSync as fstatSync2, openSync as openSync2, readFileSync as readFileSync2 } from "fs";
@@ -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.15";
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.15",
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
@@ -2,7 +2,7 @@
2
2
  "openapi": "3.0.3",
3
3
  "info": {
4
4
  "title": "Switcher API",
5
- "version": "0.2.15",
5
+ "version": "0.2.16",
6
6
  "description": "Authenticated provider/profile/catalog control plane. Launches run locally; the API never returns provider credentials."
7
7
  },
8
8
  "security": [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hasna/switcher",
3
- "version": "0.2.15",
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",