@hasna/switcher 0.2.16 → 0.2.18

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/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.16";
517
+ var version = "0.2.18";
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.16",
2573
+ version: "0.2.18",
2574
2574
  description: "Authenticated provider/profile/catalog control plane. Launches run locally; the API never returns provider credentials."
2575
2575
  },
2576
2576
  security: [
@@ -13314,7 +13314,78 @@ async function withNativeStateLock(state, operation) {
13314
13314
  }
13315
13315
  }
13316
13316
  }
13317
- async function assertShareableTree(path, budget = { entries: 0 }, depth = 0) {
13317
+ var ownedByUser = (entry) => entry.uid === process.getuid?.();
13318
+ var ownerProbe = ownedByUser;
13319
+ function strictlyInside(root, path) {
13320
+ const suffix = relative5(root, path);
13321
+ return suffix !== "" && suffix !== ".." && !suffix.startsWith("../") && !isAbsolute16(suffix);
13322
+ }
13323
+ async function assertCorpusLink(link3, root) {
13324
+ const refuse = (why) => new Fault(422, "native_state_entry", `The shared native state entry ${displayPath(link3)} is a symbolic link that ${why}. Shared entries must be regular files, directories, or links you own to another entry inside ${displayPath(root)}.`);
13325
+ const unsafe = (path) => refuse(`resolves through ${displayPath(path)}, which is not owned by you or is writable by other users. ${writeFix}`);
13326
+ const absent2 = (error) => ["ENOENT", "ENOTDIR"].includes(error.code ?? "");
13327
+ const unreadable = (path, error) => refuse(`cannot be inspected at ${displayPath(path)} (${String(error.code ?? "error").replace(/[^A-Z0-9_]/gi, "")})`);
13328
+ const inspect = async (path, operation) => {
13329
+ try {
13330
+ return await operation();
13331
+ } catch (error) {
13332
+ if (absent2(error))
13333
+ throw refuse(`is dangling (its target ${displayPath(path)} was removed); remove the link ${displayPath(link3)} to continue`);
13334
+ throw unreadable(path, error);
13335
+ }
13336
+ };
13337
+ let current = link3;
13338
+ for (let hop = 0;; hop++) {
13339
+ if (hop > 8)
13340
+ throw refuse("resolves through more than 8 links");
13341
+ const entry = await inspect(current, () => lstat8(current));
13342
+ if (!ownerProbe(entry, current))
13343
+ throw unsafe(current);
13344
+ if (!entry.isSymbolicLink()) {
13345
+ if (writableByOthers(entry))
13346
+ throw unsafe(current);
13347
+ if (entry.isDirectory() || entry.isFile() && entry.nlink === 1)
13348
+ break;
13349
+ throw refuse(`resolves to ${displayPath(current)}, which is not a directory or a regular file with a single link`);
13350
+ }
13351
+ const text = await inspect(current, () => readlink(current));
13352
+ const raw = text.startsWith("/") ? text : `${dirname8(current)}/${text}`;
13353
+ const lexical = resolve10(raw);
13354
+ if (lexical === root)
13355
+ throw refuse("points at the shared directory itself");
13356
+ if (!strictlyInside(root, lexical))
13357
+ throw refuse(`leaves ${displayPath(root)} for ${displayPath(raw)}`);
13358
+ const last = raw.slice(raw.lastIndexOf("/") + 1);
13359
+ let canonical;
13360
+ if (last === "" || last === "." || last === "..")
13361
+ canonical = await inspect(raw, () => realpath6(raw));
13362
+ else {
13363
+ const parent = await inspect(raw, () => realpath6(raw.slice(0, raw.length - last.length)));
13364
+ canonical = join17(parent, last);
13365
+ }
13366
+ if (canonical === root)
13367
+ throw refuse("points at the shared directory itself");
13368
+ if (!strictlyInside(root, canonical))
13369
+ throw refuse(`leaves ${displayPath(root)} for ${displayPath(raw)}`);
13370
+ if (strictlyInside(canonical, link3))
13371
+ throw refuse(`points at its own ancestor ${displayPath(canonical)}`);
13372
+ for (let directory = dirname8(canonical);directory !== root; directory = dirname8(directory)) {
13373
+ const item2 = await inspect(directory, () => lstat8(directory));
13374
+ if (!item2.isDirectory() || !ownerProbe(item2, directory) || writableByOthers(item2))
13375
+ throw unsafe(directory);
13376
+ }
13377
+ current = canonical;
13378
+ }
13379
+ let resolved;
13380
+ try {
13381
+ resolved = await realpath6(link3);
13382
+ } catch (error) {
13383
+ throw refuse(`does not resolve through the kernel (${String(error.code ?? "error").replace(/[^A-Z0-9_]/gi, "")})`);
13384
+ }
13385
+ if (resolved !== current)
13386
+ throw refuse(`resolves through the kernel to ${displayPath(resolved)}, not the checked ${displayPath(current)}`);
13387
+ }
13388
+ async function assertShareableTree(path, budget = { entries: 0 }, depth = 0, root = path) {
13318
13389
  if (depth > 32)
13319
13390
  throw new Fault(422, "native_state_inventory_limit", "The shared native corpus exceeds the safe projection inventory limit.");
13320
13391
  if (depth === 0)
@@ -13323,15 +13394,17 @@ async function assertShareableTree(path, budget = { entries: 0 }, depth = 0) {
13323
13394
  const nested = join17(path, child.name);
13324
13395
  if (++budget.entries > 1e5)
13325
13396
  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.`);
13397
+ if (child.isSymbolicLink()) {
13398
+ await assertCorpusLink(nested, root);
13399
+ continue;
13400
+ }
13328
13401
  const entry = await lstat8(nested);
13329
- if (entry.uid !== process.getuid?.() || writableByOthers(entry))
13402
+ if (!ownerProbe(entry, nested) || writableByOthers(entry))
13330
13403
  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}.`);
13331
13404
  if (child.isDirectory()) {
13332
13405
  if (!entry.isDirectory())
13333
13406
  throw new Fault(422, "native_state_entry", `The shared native state directory ${displayPath(nested)} changed during inspection.`);
13334
- await assertShareableTree(nested, budget, depth + 1);
13407
+ await assertShareableTree(nested, budget, depth + 1, root);
13335
13408
  continue;
13336
13409
  }
13337
13410
  if (!child.isFile() || !entry.isFile() || entry.nlink !== 1)
@@ -14071,7 +14144,11 @@ var preferences = new Set([
14071
14144
  ]);
14072
14145
  var routing3 = new Set(["model", "modelPicker", "fallbackModel", "modelSettings"]);
14073
14146
  var credentialHelpers = new Set(["apiKeyHelper", "awsAuthRefresh", "awsCredentialExport", "otelHeadersHelper", "forceLoginMethod", "forceLoginOrgUUID"]);
14147
+ var budgetEnvironmentKeys = new Set(["MAX_THINKING_TOKENS", "CLAUDE_CODE_MAX_OUTPUT_TOKENS", "MAX_MCP_OUTPUT_TOKENS", "CLAUDE_CODE_MAX_CONTEXT_TOKENS"]);
14148
+ var routingEnvironmentKeys = new Set(["CLAUDE_CODE_SUBAGENT_MODEL", "CLAUDE_CODE_SUBAGENT_MODEL_FORCE"]);
14074
14149
  function routingOrCredentialEnvironmentKey(key) {
14150
+ if (budgetEnvironmentKeys.has(key))
14151
+ return false;
14075
14152
  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
14153
  }
14077
14154
  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.`);
@@ -14118,14 +14195,20 @@ function project(settings2, existing, path) {
14118
14195
  if (key === "env") {
14119
14196
  if (!value || typeof value !== "object" || Array.isArray(value))
14120
14197
  throw unsupported3("env", "which is not an object of string values");
14198
+ const environment = {};
14121
14199
  for (const [name, item2] of Object.entries(value)) {
14200
+ if (routingEnvironmentKeys.has(name)) {
14201
+ dropped.push(`env.${name}`);
14202
+ continue;
14203
+ }
14122
14204
  if (routingOrCredentialEnvironmentKey(name))
14123
14205
  throw unsupported3(`env.${name}`, "which routes or authenticates requests or may carry a credential");
14124
14206
  if (typeof item2 !== "string")
14125
14207
  throw unsupported3(`env.${name}`, "which is not a string");
14208
+ environment[name] = item2;
14126
14209
  }
14127
- if (Object.keys(value).length)
14128
- result[key] = value;
14210
+ if (Object.keys(environment).length)
14211
+ result[key] = environment;
14129
14212
  continue;
14130
14213
  }
14131
14214
  if (!preferences.has(key)) {
@@ -14251,7 +14334,7 @@ async function prepareClaudeDesktopLaunch(input, app, sessionDir, system) {
14251
14334
  // src/codex-session-discovery.ts
14252
14335
  import { spawn as spawn3 } from "child_process";
14253
14336
  import { createInterface as createInterface2 } from "readline/promises";
14254
- import { basename as basename3, resolve as resolve12 } from "path";
14337
+ import { basename as basename4, resolve as resolve12 } from "path";
14255
14338
  var object6 = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
14256
14339
  var unavailable2 = () => new Fault(422, "codex_session_discovery", "Native Codex session discovery failed. No conversation was started. Retry discovery or provide an exact session ID.");
14257
14340
  async function listCodexSessions(prepared, cwd, query) {
@@ -14420,7 +14503,7 @@ async function resolveCodexResumeArguments(prepared, nativeArgs, cwd, list = lis
14420
14503
  try {
14421
14504
  for (;; ) {
14422
14505
  console.error("Codex conversations across providers:");
14423
- page.data.forEach((thread, i) => console.error(` ${i + 1}. ${display(thread.name ?? thread.id)} \u2014 workspace ${display(basename3(thread.cwd) || "unknown")}`));
14506
+ page.data.forEach((thread, i) => console.error(` ${i + 1}. ${display(thread.name ?? thread.id)} \u2014 workspace ${display(basename4(thread.cwd) || "unknown")}`));
14424
14507
  const answer = (await reader.question("Number, search text, or n for next page (Ctrl-C cancels): ", { signal: controller.signal }).catch((error) => {
14425
14508
  throw controller.signal.aborted ? controller.signal.reason : error;
14426
14509
  })).trim();
@@ -14458,7 +14541,7 @@ import { closeSync as closeSync3, openSync as openSync3 } from "fs";
14458
14541
  import { createHash as createHash16, randomBytes as randomBytes2, randomUUID as randomUUID7 } from "crypto";
14459
14542
  import { constants as constants10 } from "fs";
14460
14543
  import { chmod as chmod3, lstat as lstat10, mkdir as mkdir12, open as open7, readdir as readdir7, rename as rename4, rm as rm5, unlink as unlink3 } from "fs/promises";
14461
- import { basename as basename4, dirname as dirname9, isAbsolute as isAbsolute17, join as join22, resolve as resolve13 } from "path";
14544
+ import { basename as basename5, dirname as dirname9, isAbsolute as isAbsolute17, join as join22, resolve as resolve13 } from "path";
14462
14545
  import { z as z10 } from "zod";
14463
14546
 
14464
14547
  // src/process-table.ts
@@ -14831,7 +14914,7 @@ async function writePrivate(path, text) {
14831
14914
  async function launchStateDirectory(path) {
14832
14915
  if (path === undefined)
14833
14916
  return;
14834
- if (!isAbsolute17(path) || resolve13(path) !== path || !/^launch-[A-Za-z0-9]{6}$/.test(basename4(path)))
14917
+ if (!isAbsolute17(path) || resolve13(path) !== path || !/^launch-[A-Za-z0-9]{6}$/.test(basename5(path)))
14835
14918
  throw new Fault(400, "invalid_state_dir", "The launch state directory must be an absolute launch-XXXXXX directory.");
14836
14919
  const info2 = await lstat10(path).catch(() => {
14837
14920
  return;
@@ -16174,7 +16257,7 @@ async function ensureLaunchProfile(client, provider, harness, model3, modelPolic
16174
16257
  import { createHash as createHash18 } from "crypto";
16175
16258
  import { constants as constants11 } from "fs";
16176
16259
  import { lstat as lstat12, open as open9, opendir as opendir2, link as link3, rmdir as rmdir2, unlink as unlink5 } from "fs/promises";
16177
- import { basename as basename5, dirname as dirname11, isAbsolute as isAbsolute19, join as join25, relative as relative6, resolve as resolve15 } from "path";
16260
+ import { basename as basename6, dirname as dirname11, isAbsolute as isAbsolute19, join as join25, relative as relative6, resolve as resolve15 } from "path";
16178
16261
  var MAX_FILES = 1e5;
16179
16262
  var MAX_BYTES2 = 2 * 1024 * 1024 * 1024;
16180
16263
  var refused = () => new Fault(409, "native_state_import_conflict", "Native state import found changed, unsafe or divergent data. No existing file will be replaced. Keep the original directory and resolve the conflict explicitly.");
@@ -16195,7 +16278,7 @@ var inside3 = (parent, child) => {
16195
16278
  };
16196
16279
  var SESSION_ID = /^[a-f\d]{8}(?:-[a-f\d]{4}){3}-[a-f\d]{12}$/i;
16197
16280
  async function sessionId(path, expected) {
16198
- const nameId = basename5(path).match(/([a-f\d]{8}(?:-[a-f\d]{4}){3}-[a-f\d]{12})\.jsonl$/i)?.[1]?.toLowerCase();
16281
+ const nameId = basename6(path).match(/([a-f\d]{8}(?:-[a-f\d]{4}){3}-[a-f\d]{12})\.jsonl$/i)?.[1]?.toLowerCase();
16199
16282
  const handle = await open9(path, constants11.O_RDONLY | constants11.O_NOFOLLOW);
16200
16283
  try {
16201
16284
  const before = await handle.stat();
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.16";
4052
+ var version = "0.2.18";
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.16",
7083
+ version: "0.2.18",
7084
7084
  description: "Authenticated provider/profile/catalog control plane. Launches run locally; the API never returns provider credentials."
7085
7085
  },
7086
7086
  security: [
@@ -39,6 +39,30 @@ export declare function ensureNativeStateDirectory(path: string, create?: boolea
39
39
  * Keep existing links intact; a different isolated profile is an explicit choice. */
40
40
  export declare function assertNativeStateIsolation(tool: SharedNativeTool, home: string, environment?: NodeJS.ProcessEnv): Promise<void>;
41
41
  export declare function withNativeStateLock<T>(state: NativeState, operation: () => Promise<T>): Promise<T>;
42
+ type OwnerProbe = (entry: Stats, path: string) => boolean;
43
+ /** Tests only: replace the owned-by-you predicate for shared corpus entries. Omit the probe to restore it. */
44
+ export declare function setOwnerProbeForTesting(probe?: OwnerProbe): void;
45
+ /** Claude Code links one session's transcript to another's when a session
46
+ * resumes under a new id. This applies to every shared top-level directory of
47
+ * either tool (Claude projects, todos, skills, instructions; Codex sessions,
48
+ * skills and the others). A link is accepted only when:
49
+ * - the link and every further link hop are owned by you (ownership only: a
50
+ * link's mode bits are not consulted, and Linux links are always 0777);
51
+ * - each hop, resolved in kernel order (the link text joined by concatenation,
52
+ * never normalised; the directory part resolved by realpath before the last
53
+ * segment applies, so a ".." after a directory link is checked where the
54
+ * kernel takes it), lies strictly inside the real path of the same top-level
55
+ * directory, is not that directory and is not an ancestor of the link;
56
+ * - every real directory from that hop's resolved parent up to, not including,
57
+ * the top-level directory is owned by you and not writable by others;
58
+ * - the final target is owned by you, not writable by others, and a directory
59
+ * (walked separately) or a regular file with a single link;
60
+ * - the kernel's own realpath of the link equals the checked target.
61
+ * Directories outside the corpus that the link text names before realpath
62
+ * collapses them are not checked; the resolved target must still be inside.
63
+ * Every failure, including any errno, refuses with the link's path. Switcher
64
+ * never writes through an accepted link. */
65
+ export declare function assertCorpusLink(link: string, root: string): Promise<void>;
42
66
  /** A nested CLI keeps its authentication home. Refuse conflicting instruction
43
67
  * overlays rather than rewriting account config or exposing instructions in argv. */
44
68
  export declare function assertNativeInstructionOverlay(state: NativeState, overlayHome: string): Promise<void>;
@@ -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.16";
71
+ var version = "0.2.18";
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.16",
925
+ version: "0.2.18",
926
926
  description: "Authenticated provider/profile/catalog control plane. Launches run locally; the API never returns provider credentials."
927
927
  },
928
928
  security: [
@@ -4,7 +4,7 @@
4
4
  "name": "switcher",
5
5
  "class": "cli-with-store",
6
6
  "contractVersion": "v1",
7
- "kitVersion": "1.3.8",
7
+ "kitVersion": "1.3.10",
8
8
  "description": "Universal provider and model switcher with API-first local and hosted operation. CLI, MCP and SDK resolve one authenticated HTTP authority through @hasna/contracts and fail closed when hosted configuration is missing or invalid. HASNA_SWITCHER_LOCAL=1 deliberately selects an owned loopback API backed by SQLite; hosted https://api.hasna.com/switcher uses PostgreSQL and signed revocable API keys. Provider credentials remain local to the launcher and are never stored or returned by the service.",
9
9
  "bins": [
10
10
  "switcher",
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.16",
5
+ "version": "0.2.18",
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.16",
3
+ "version": "0.2.18",
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",
@@ -78,8 +78,8 @@
78
78
  "@types/pg": "8.23.1"
79
79
  },
80
80
  "dependencies": {
81
- "@hasna/contracts": "1.3.8",
82
- "@modelcontextprotocol/sdk": "1.32.1",
81
+ "@hasna/contracts": "1.3.10",
82
+ "@modelcontextprotocol/sdk": "^1.29.0",
83
83
  "jsonc-parser": "3.3.1",
84
84
  "yaml": "2.9.0",
85
85
  "zod": "3.25.76",