@hasna/switcher 0.2.10 → 0.2.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -112,9 +112,9 @@ every provider. See the [browser extension guide](https://learn.chatgpt.com/docs
112
112
  and [DeepSeek compatibility details](https://api-docs.deepseek.com/guides/responses_api/).
113
113
 
114
114
  Switcher starts a separate app instance with private login and Electron state.
115
- That private overlay remains provider/profile-scoped. `--share-native-state` (or
116
- an explicit shared-state marker below) projects only the allowlisted native corpus
117
- into that overlay, so local conversations and instructions can remain available
115
+ That private overlay remains provider/profile-scoped. For Codex, `--share-native-state`
116
+ (or an explicit shared-state marker below) projects only the allowlisted native corpus
117
+ into that overlay, so local conversations, skills and instructions can remain available
118
118
  without reusing another provider/account's cookies, settings or authentication.
119
119
  The canonical Codex corpus is normally `~/.codex`. Your regular ChatGPT app's
120
120
  signed-in state is preserved; authentication and cookies are not copied. A second
@@ -131,32 +131,60 @@ installation with `--app-path /absolute/path/ChatGPT.app`; native CLI arguments,
131
131
 
132
132
  ### Shared native conversations
133
133
 
134
- Sharing is opt-in. Pass `--share-native-state`, set
135
- `HASNA_CODEX_STATE_HOME`/`HASNA_CLAUDE_STATE_HOME`, or set the compatible
134
+ Claude CLI and desktop share their canonical sessions, skills and instructions by
135
+ default. `--no-share-native-state` explicitly disables this projection, even when
136
+ a state marker is inherited. For CLI launches without a configured native home,
137
+ it selects a persistent private home for that Switcher profile. Existing shared
138
+ links, canonical-home overlap or redirected Codex databases refuse isolation;
139
+ Switcher never unlinks them or rewrites their configuration. Select a separate
140
+ profile to keep isolated state. Ori refuses explicit isolation until its native
141
+ state contract is verified; use the direct backend.
142
+ The existing `--share-native-state` flag remains supported; passing both flags is
143
+ an error. Programmatic callers use `shareNativeState: false` for the same opt-out.
144
+
145
+ Codex CLI and ChatGPT default sharing remains pending native writer/artifact
146
+ admission for the private-authentication/shared-corpus contract. Their existing
147
+ `--share-native-state` and marker paths remain available with all current version,
148
+ instruction, collision and adapter checks; a version string alone does not establish
149
+ that broader compatibility. This is a remaining implementation prerequisite.
150
+
151
+ The default corpus is `~/.codex` or `~/.claude`. To select another canonical corpus,
152
+ set `HASNA_CODEX_STATE_HOME`/`HASNA_CLAUDE_STATE_HOME`, or the compatible
136
153
  `SUBSCRIPTIONS_SHARED_HOME_CODEX`/`SUBSCRIPTIONS_SHARED_HOME_CLAUDE` marker.
137
- Without one of those signals, Switcher keeps its historical provider/account state
138
- layout and creates no shared links. The command flag selects `~/.codex` or
139
- `~/.claude`; a custom canonical corpus must be named by a marker. Ambient
140
- `CODEX_HOME`/`CLAUDE_CONFIG_DIR` is treated only as the current private overlay,
141
- never silently promoted into the cross-account identity. If both marker forms are
142
- present they must resolve to the same directory. Markers are consumed by Switcher
143
- and are not forwarded to provider processes or nested launchers. Directories must
144
- be absolute, owned and free of writable/symlink redirection. This contract is
145
- currently supported on Linux and macOS; Windows refuses before creating state.
146
-
147
- Codex overlays share sessions, archived sessions and `thread-writer-locks`. Native
148
- skill directories are deliberately excluded: Skills-owned migration and hook
149
- controls remain authoritative and account-synced skill copies must not enter a
150
- cross-account corpus. The entire SQLite store uses the canonical
154
+ Ambient `CODEX_HOME`/`CLAUDE_CONFIG_DIR` selects the current private overlay, never
155
+ the cross-account identity. If both marker forms are present they must resolve
156
+ to the same directory. Markers are consumed by Switcher and are not forwarded to
157
+ provider processes or nested launchers. Directories must be absolute, owned and
158
+ free of writable/symlink redirection. Shared projection is supported on Linux
159
+ and macOS; Windows refuses before creating state. An explicit opt-out validates
160
+ corpus identities to reject overlap, without creating a canonical corpus.
161
+
162
+ Codex overlays share sessions, archived sessions, `thread-writer-locks` and
163
+ `skills`. Skill directories use the same guarded projection as sessions: edits
164
+ and deletions remain visible across overlays, and no account copy is merged over
165
+ the canonical Skills projection. Skills-owned authoring, migration and hooks
166
+ remain authoritative. The entire SQLite store uses the canonical
151
167
  configuration's `sqlite_home`, or the canonical root; inherited account-specific
152
168
  `CODEX_SQLITE_HOME` is ignored. There are no per-database or WAL symlinks.
153
169
  `session_index.jsonl` stays an overlay-local native index; legacy index-only names
154
170
  remain pending explicit migration. Authentication,
155
171
  Electron cookies, `.codex-global-state.json`, plugin caches and worktree metadata
156
- are not projected between homes. Claude's projects, todos, history and explicit `CLAUDE.md`/`.hasna/instructions`
157
- policy roots use its common corpus. Commands, agents, rules, credentials, settings,
158
- native skills and plugin state remain private. Skills continue through the
159
- reviewed Skills bridge.
172
+ are not projected between homes. Claude's projects (including their native
173
+ project memories), todos, skills, history and explicit `CLAUDE.md`/`.hasna/instructions`
174
+ policy roots use its common corpus. Commands, agents, rules, credentials, settings
175
+ and plugin state remain private. Skills continue through the reviewed Skills bridge.
176
+ For a new Claude private home, Switcher seeds supported user settings from the
177
+ effective `CLAUDE_CONFIG_DIR` (or `~/.claude`), including permissions, sandbox policy,
178
+ language, output style, thinking/effort and display preferences. The copy stays at
179
+ user-settings scope, so native project/local and managed precedence is preserved.
180
+ Existing private settings and later native edits are retained without overwrite;
181
+ later changes to the original user file are not automatically merged. The selected
182
+ Switcher profile owns model/picker routing. Environment, credential helpers,
183
+ hooks/plugins and other unsupported settings refuse before launch instead of
184
+ silently dropping policy or copying credentials. Authentication files are never copied.
185
+ Existing private skill directories and unsafe links fail before any projection.
186
+ Legacy `state import` still excludes skills: it must not resurrect removed
187
+ Skills-owned entries from an old account copy.
160
188
 
161
189
  Both tools share only `.hasna/instructions`, never the rest of `.hasna`. Codex's
162
190
  optional `AGENTS.override.md` takes native precedence over `AGENTS.md`; Switcher
@@ -719,7 +747,7 @@ Grok uses a per-launch authenticated loopback bridge because its environment ove
719
747
 
720
748
  Hermes uses the same loopback boundary with its documented `custom` provider. The bridge exposes only the Switcher catalog, translates the selected provider's Bearer, `x-api-key` or literal `api-key` credential, and forwards deployment prefixes unchanged. Hermes `state.db` and `sessions/` are linked to a profile-owned stable directory for resume; generated config and bridge credentials remain per-launch. Focused bridge tests cover all three native protocol routes and auth styles, including cleanup of an active stream without caller cancellation. Run `bun scripts/test-native-hermes.ts` with `SWITCHER_TEST_HERMES_EXECUTABLE` for the installed native CLI fixture proof, which performs a real `read_file` loop and deleted-file resume against a generic preset.
721
749
 
722
- Codex and Claude can use their [shared native corpus](#shared-native-conversations) only after explicit command or environment consent. Sessions and reviewed instruction roots may cross provider/account overlays; authentication, native skills, settings, plugins and broader capability trees remain private. Other harnesses retain their documented native storage and resume restrictions; cross-provider conversion of incompatible reasoning or session formats is not provided. Temporary nonsecret picker/config files are removed when the child exits. Run records contain launch/end metadata and initial model, not transcripts or a claim about later native picker selections.
750
+ Claude uses its [shared native corpus](#shared-native-conversations) by default, with explicit isolation available. Codex default sharing awaits native writer admission; its existing command/marker selection remains supported. Sessions, skills and reviewed instruction roots may cross provider/account overlays; authentication, settings, plugins and broader capability trees remain private. Other harnesses retain their documented native storage and resume restrictions; cross-provider conversion of incompatible reasoning or session formats is not provided. Temporary nonsecret picker/config files are removed when the child exits. Run records contain launch/end metadata and initial model, not transcripts or a claim about later native picker selections.
723
751
 
724
752
  ## SDK and API
725
753
 
@@ -0,0 +1,3 @@
1
+ /** 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>;
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.10";
517
+ var version = "0.2.11";
518
518
 
519
519
  // src/version.ts
520
520
  var VERSION = version;
@@ -1109,6 +1109,7 @@ function assertHarnessArguments(harness, args, options = {}) {
1109
1109
 
1110
1110
  // src/cli.ts
1111
1111
  import { parseArgs } from "util";
1112
+ import { join as join23, resolve as resolve14 } from "path";
1112
1113
 
1113
1114
  // src/http.ts
1114
1115
  var MAX_BYTES = 16 * 1024 * 1024;
@@ -1371,9 +1372,14 @@ async function detectChatGPTApp(appPath, system = host) {
1371
1372
  const name = await field("CFBundleExecutable"), version2 = await field("CFBundleShortVersionString");
1372
1373
  if (!/^[A-Za-z0-9 _-]+$/.test(name))
1373
1374
  continue;
1374
- const executable = join3(path, "Contents/MacOS", name), codexExecutable = join3(path, "Contents/Resources/codex");
1375
- if (await system.executable(executable) && await system.executable(codexExecutable))
1376
- return { path, executable, codexExecutable, bundleId, version: version2 };
1375
+ const executable = join3(path, "Contents/MacOS", name);
1376
+ if (!await system.executable(executable))
1377
+ continue;
1378
+ for (const relative2 of ["Contents/Resources/codex", "Contents/Resources/codex-cli/CodexCLI.app/Contents/MacOS/codex"]) {
1379
+ const codexExecutable = join3(path, relative2);
1380
+ if (await system.executable(codexExecutable))
1381
+ return { path, executable, codexExecutable, bundleId, version: version2 };
1382
+ }
1377
1383
  } catch {}
1378
1384
  }
1379
1385
  throw new Fault(404, "app_not_installed", "Install the current ChatGPT/Codex macOS app or use --app-path with its absolute .app path. Legacy ChatGPT Classic cannot run custom Codex providers.");
@@ -2543,7 +2549,7 @@ var openapi_default = {
2543
2549
  openapi: "3.0.3",
2544
2550
  info: {
2545
2551
  title: "Switcher API",
2546
- version: "0.2.10",
2552
+ version: "0.2.11",
2547
2553
  description: "Authenticated provider/profile/catalog control plane. Launches run locally; the API never returns provider credentials."
2548
2554
  },
2549
2555
  security: [
@@ -11323,8 +11329,8 @@ exec "$SWITCHER_ORI_NATIVE_EXECUTABLE" ${prepared.args.map(quote2).join(" ")}
11323
11329
  }
11324
11330
 
11325
11331
  // src/launcher.ts
11326
- import { mkdir as mkdir12, mkdtemp, rm as rm6, writeFile as writeFile17 } from "fs/promises";
11327
- import { join as join20, resolve as resolve11 } from "path";
11332
+ import { mkdir as mkdir12, mkdtemp, rm as rm6, writeFile as writeFile18 } from "fs/promises";
11333
+ import { join as join21, resolve as resolve12 } from "path";
11328
11334
 
11329
11335
  // src/provider-credential-onboarding.ts
11330
11336
  import { z as z9 } from "zod";
@@ -12677,9 +12683,11 @@ import { lstat as lstat8, mkdir as mkdir11, open as open4, opendir, readlink, re
12677
12683
  import { constants as constants7 } from "fs";
12678
12684
  import { homedir as homedir9 } from "os";
12679
12685
  import { dirname as dirname8, isAbsolute as isAbsolute16, join as join17, relative as relative5, resolve as resolve9 } from "path";
12680
- function nativeStateRequested(tool, environment = process.env, explicit = false) {
12686
+ function nativeStateRequested(tool, environment = process.env, explicit) {
12687
+ if (explicit !== undefined)
12688
+ return explicit;
12681
12689
  const suffix = tool.toUpperCase();
12682
- return explicit || environment[`HASNA_${suffix}_STATE_HOME`] !== undefined || environment[`SUBSCRIPTIONS_SHARED_HOME_${suffix}`] !== undefined;
12690
+ return tool === "claude" || environment[`HASNA_${suffix}_STATE_HOME`] !== undefined || environment[`SUBSCRIPTIONS_SHARED_HOME_${suffix}`] !== undefined;
12683
12691
  }
12684
12692
  function validateNativeStateVersion(tool, version2) {
12685
12693
  if (tool !== "codex")
@@ -12703,11 +12711,11 @@ var CODEX_INSTRUCTION_KEYS = [
12703
12711
  ];
12704
12712
  var NATIVE_STATE_ENTRIES = {
12705
12713
  codex: [
12706
- ...["sessions", "archived_sessions", "thread-writer-locks", ".hasna/instructions"].map((name) => ({ name, kind: "directory" })),
12714
+ ...["sessions", "archived_sessions", "thread-writer-locks", "skills", ".hasna/instructions"].map((name) => ({ name, kind: "directory" })),
12707
12715
  ...["history.jsonl", "AGENTS.md", "AGENTS.override.md"].map((name) => ({ name, kind: "file" }))
12708
12716
  ],
12709
12717
  claude: [
12710
- ...["projects", "todos", ".hasna/instructions"].map((name) => ({ name, kind: "directory" })),
12718
+ ...["projects", "todos", "skills", ".hasna/instructions"].map((name) => ({ name, kind: "directory" })),
12711
12719
  ...["history.jsonl", "CLAUDE.md"].map((name) => ({ name, kind: "file" }))
12712
12720
  ]
12713
12721
  };
@@ -12756,6 +12764,30 @@ async function ensureNativeStateDirectory(path, create = true) {
12756
12764
  });
12757
12765
  await assertNativeStateDirectory(path);
12758
12766
  }
12767
+ async function assertNativeStateIsolation(tool, home, environment = process.env) {
12768
+ home = absolute(home);
12769
+ const canonical = await resolveNativeState(tool, environment, { create: false });
12770
+ const roots = [canonical.home, canonical.sqliteHome, join17(absolute(environment.HOME ?? homedir9()), `.${tool}`)];
12771
+ const contains = (parent, child) => {
12772
+ const path = relative5(parent, child);
12773
+ return path !== ".." && !path.startsWith("../") && !isAbsolute16(path);
12774
+ };
12775
+ if (roots.some((root) => root && (contains(root, home) || contains(home, root))))
12776
+ throw new Fault(409, "native_state_isolation_conflict", "The isolated home overlaps a canonical native corpus or database. Select a distinct private home; Switcher will not alter existing state.");
12777
+ if (!await info(home))
12778
+ return;
12779
+ await assertNativeStateDirectory(home);
12780
+ for (const { name } of NATIVE_STATE_ENTRIES[tool]) {
12781
+ await ensureNativeStateDirectory(dirname8(join17(home, name)), false);
12782
+ if ((await info(join17(home, name)))?.isSymbolicLink())
12783
+ throw new Fault(409, "native_state_isolation_conflict", "This profile already links native state. Select a separate isolated profile; Switcher will not remove its existing shared links.");
12784
+ }
12785
+ if (tool === "codex") {
12786
+ const config = await readCodexStateConfig(home);
12787
+ if (config.sqlite_home !== undefined && (typeof config.sqlite_home !== "string" || absolute(config.sqlite_home) !== home))
12788
+ throw new Fault(409, "native_state_isolation_conflict", "This profile redirects its native database. Select a separate isolated profile; Switcher will not rewrite its existing configuration.");
12789
+ }
12790
+ }
12759
12791
  async function withNativeStateLock(state, operation) {
12760
12792
  await ensureNativeStateDirectory(state.home);
12761
12793
  const path = join17(state.home, ".switcher-shared-state.lock");
@@ -13214,15 +13246,119 @@ ${bridge}exec ${quote2(app.codexExecutable)} "$@" ${overrides.map(quote2).join("
13214
13246
  // src/claude-desktop-launch.ts
13215
13247
  import { createHash as createHash13 } from "crypto";
13216
13248
  import { execFile as execFile5 } from "child_process";
13217
- import { access as access4, rm as rm5, writeFile as writeFile16 } from "fs/promises";
13218
- import { homedir as homedir10, userInfo as userInfo2 } from "os";
13219
- import { join as join19 } from "path";
13249
+ import { access as access4, rm as rm5, writeFile as writeFile17 } from "fs/promises";
13250
+ import { homedir as homedir11, userInfo as userInfo2 } from "os";
13251
+ import { join as join20 } from "path";
13220
13252
  import { promisify as promisify5 } from "util";
13253
+
13254
+ // src/claude-user-settings.ts
13255
+ import { constants as constants8 } from "fs";
13256
+ import { lstat as lstat9, open as open5, writeFile as writeFile16 } from "fs/promises";
13257
+ import { homedir as homedir10 } from "os";
13258
+ import { join as join19, resolve as resolve10 } from "path";
13259
+ var preferences = new Set([
13260
+ "$schema",
13261
+ "permissions",
13262
+ "sandbox",
13263
+ "language",
13264
+ "outputStyle",
13265
+ "alwaysThinkingEnabled",
13266
+ "effortLevel",
13267
+ "cleanupPeriodDays",
13268
+ "autoUpdatesChannel",
13269
+ "includeCoAuthoredBy",
13270
+ "attribution",
13271
+ "respectGitignore",
13272
+ "spinnerTipsEnabled",
13273
+ "spinnerVerbs",
13274
+ "spinnerTipsOverride",
13275
+ "terminalProgressBarEnabled",
13276
+ "prefersReducedMotion",
13277
+ "showTurnDuration",
13278
+ "showClearContextOnPlanAccept",
13279
+ "showCompactionHistory",
13280
+ "teammateMode"
13281
+ ]);
13282
+ var routing3 = new Set(["model", "modelPicker", "fallbackModel"]);
13283
+ var invalid3 = () => 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.");
13284
+ async function readSettings(home) {
13285
+ await ensureNativeStateDirectory(home, false);
13286
+ const path = join19(home, "settings.json");
13287
+ const entry = await lstat9(path).catch((error) => {
13288
+ if (error.code === "ENOENT")
13289
+ return;
13290
+ throw error;
13291
+ });
13292
+ if (!entry)
13293
+ return;
13294
+ if (!entry.isFile() || entry.isSymbolicLink() || entry.nlink !== 1 || entry.uid !== process.getuid?.() || (entry.mode & 18) !== 0 || entry.size > 1024 * 1024)
13295
+ throw invalid3();
13296
+ const handle = await open5(path, constants8.O_RDONLY | constants8.O_NOFOLLOW);
13297
+ try {
13298
+ const opened = await handle.stat();
13299
+ if (opened.dev !== entry.dev || opened.ino !== entry.ino || opened.nlink !== 1 || opened.size > 1024 * 1024)
13300
+ throw invalid3();
13301
+ const value = JSON.parse(await handle.readFile("utf8"));
13302
+ if (!value || typeof value !== "object" || Array.isArray(value))
13303
+ throw invalid3();
13304
+ return value;
13305
+ } catch (error) {
13306
+ if (error instanceof Fault)
13307
+ throw error;
13308
+ throw invalid3();
13309
+ } finally {
13310
+ await handle.close();
13311
+ }
13312
+ }
13313
+ function project(settings2, existing) {
13314
+ const result = {};
13315
+ for (const [key, value] of Object.entries(settings2)) {
13316
+ if (routing3.has(key)) {
13317
+ if (existing && key === "fallbackModel")
13318
+ throw new Fault(409, "claude_settings_routing", "The private Claude settings select a fallback model. Resolve that conflict with the Switcher profile before launching.");
13319
+ continue;
13320
+ }
13321
+ if (key === "env" && value && typeof value === "object" && !Array.isArray(value) && Object.keys(value).length === 0)
13322
+ continue;
13323
+ if (!preferences.has(key))
13324
+ 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.");
13325
+ result[key] = value;
13326
+ }
13327
+ return result;
13328
+ }
13329
+ async function prepareClaudeUserSettings(overlayHome, environment = process.env) {
13330
+ overlayHome = resolve10(overlayHome);
13331
+ const existing = await readSettings(overlayHome);
13332
+ if (existing !== undefined) {
13333
+ project(existing, true);
13334
+ return;
13335
+ }
13336
+ const sourceHome = resolve10(environment.CLAUDE_CONFIG_DIR ?? join19(environment.HOME ?? homedir10(), ".claude"));
13337
+ if (sourceHome === overlayHome)
13338
+ return;
13339
+ const source = await readSettings(sourceHome);
13340
+ if (source === undefined)
13341
+ return;
13342
+ const settings2 = project(source, false);
13343
+ await ensureNativeStateDirectory(overlayHome);
13344
+ try {
13345
+ await writeFile16(join19(overlayHome, "settings.json"), JSON.stringify(settings2, null, 2) + `
13346
+ `, { mode: 384, flag: "wx" });
13347
+ } catch (error) {
13348
+ if (error.code !== "EEXIST")
13349
+ throw error;
13350
+ const concurrent = await readSettings(overlayHome);
13351
+ if (concurrent === undefined || JSON.stringify(project(concurrent, true)) !== JSON.stringify(settings2))
13352
+ 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.");
13353
+ }
13354
+ }
13355
+
13356
+ // src/claude-desktop-launch.ts
13221
13357
  var execute4 = promisify5(execFile5);
13222
13358
  var hash2 = (text) => createHash13("sha256").update(text).digest("hex");
13223
- var claudeDesktopDataDirectory = () => join19(homedir10(), "Library/Application Support/Claude-3p");
13359
+ var claudeDesktopDataDirectory = () => join20(homedir11(), "Library/Application Support/Claude-3p");
13224
13360
  async function assertAvailable(userData) {
13225
- for (const path of [join19("/Library/Managed Preferences", userInfo2().username, "com.anthropic.claudefordesktop.plist"), "/Library/Managed Preferences/com.anthropic.claudefordesktop.plist"])
13361
+ for (const path of [join20("/Library/Managed Preferences", userInfo2().username, "com.anthropic.claudefordesktop.plist"), "/Library/Managed Preferences/com.anthropic.claudefordesktop.plist"])
13226
13362
  if (await access4(path).then(() => true, () => false))
13227
13363
  throw new Fault(409, "desktop_managed", "Claude has managed preferences. Configure its gateway through the administrator's policy; Switcher will not override it.");
13228
13364
  let openFiles;
@@ -13258,15 +13394,15 @@ async function prepareClaudeDesktopLaunch(input, app, sessionDir, system) {
13258
13394
  const check2 = system?.assertAvailable ?? (() => assertAvailable(userData));
13259
13395
  await check2();
13260
13396
  await privateDirectory(userData);
13261
- const library = join19(userData, "configLibrary");
13397
+ const library = join20(userData, "configLibrary");
13262
13398
  await privateDirectory(library);
13263
- const release = await desktopLease(join19(library, ".switcher-lease.sqlite"));
13264
- const metaPath = join19(library, "_meta.json"), receiptPath = join19(library, ".switcher-selection.json");
13399
+ const release = await desktopLease(join20(library, ".switcher-lease.sqlite"));
13400
+ const metaPath = join20(library, "_meta.json"), receiptPath = join20(library, ".switcher-selection.json");
13265
13401
  let receipt, gateway, closed = false;
13266
13402
  const restore = async (record3) => {
13267
13403
  if (!/^[a-f0-9-]{36}$/.test(record3.id) || typeof record3.configHash !== "string" || typeof record3.appliedMeta !== "string" || record3.previousMeta !== null && typeof record3.previousMeta !== "string")
13268
13404
  throw new Fault(422, "desktop_config_invalid", "Claude's Switcher recovery record is invalid.");
13269
- const configPath = join19(library, record3.id + ".json"), current = await safeDesktopRead(configPath);
13405
+ const configPath = join20(library, record3.id + ".json"), current = await safeDesktopRead(configPath);
13270
13406
  if (current !== undefined && hash2(current) !== record3.configHash)
13271
13407
  throw new Fault(409, "desktop_config_changed", "The Switcher Claude configuration was edited outside this launch. Switcher will preserve it; review the configuration library before relaunching.");
13272
13408
  const currentMeta = await safeDesktopRead(metaPath);
@@ -13295,9 +13431,11 @@ async function prepareClaudeDesktopLaunch(input, app, sessionDir, system) {
13295
13431
  const recovery = await safeDesktopRead(receiptPath);
13296
13432
  if (recovery)
13297
13433
  await restore(JSON.parse(recovery));
13298
- const localConfig = await safeDesktopRead(join19(userData, "claude_desktop_config.json"));
13434
+ const localConfig = await safeDesktopRead(join20(userData, "claude_desktop_config.json"));
13299
13435
  if (localConfig && JSON.parse(localConfig).deploymentMode === "1p")
13300
13436
  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.");
13437
+ if (input.sharedState)
13438
+ await prepareClaudeUserSettings(sessionDir);
13301
13439
  await privateDirectory(sessionDir);
13302
13440
  if (input.sharedState)
13303
13441
  await projectNativeState(input.sharedState, sessionDir);
@@ -13308,10 +13446,10 @@ async function prepareClaudeDesktopLaunch(input, app, sessionDir, system) {
13308
13446
  if (input.modelPolicy?.aliases?.[alias] && input.modelPolicy.aliases[alias] !== target)
13309
13447
  throw new Fault(409, "desktop_alias_conflict", "The model policy conflicts with Claude desktop's reserved switcher/sonnet, switcher/opus or switcher/haiku routing aliases.");
13310
13448
  const compiledPolicy = compileModelPolicy(input.model, input.models, { ...input.modelPolicy, version: 1, aliases: { ...input.modelPolicy?.aliases, ...aliases } });
13311
- const catalogPath = join19(input.stateDir, "claude-desktop-policy.json");
13312
- await writeFile16(catalogPath, JSON.stringify({ policy: compiledPolicy, models: input.models }), { mode: 384, flag: "wx" });
13449
+ const catalogPath = join20(input.stateDir, "claude-desktop-policy.json");
13450
+ await writeFile17(catalogPath, JSON.stringify({ policy: compiledPolicy, models: input.models }), { mode: 384, flag: "wx" });
13313
13451
  gateway = createInferenceGateway({ ...input, compiledPolicy, catalogPath });
13314
- const id2 = crypto.randomUUID(), configPath = join19(library, id2 + ".json");
13452
+ const id2 = crypto.randomUUID(), configPath = join20(library, id2 + ".json");
13315
13453
  const config = JSON.stringify({
13316
13454
  inferenceProvider: "gateway",
13317
13455
  inferenceGatewayBaseUrl: gateway.baseUrl.replace(/\/v1$/, ""),
@@ -13347,7 +13485,7 @@ async function prepareClaudeDesktopLaunch(input, app, sessionDir, system) {
13347
13485
  // src/codex-session-discovery.ts
13348
13486
  import { spawn as spawn3 } from "child_process";
13349
13487
  import { createInterface as createInterface2 } from "readline/promises";
13350
- import { basename as basename3, resolve as resolve10 } from "path";
13488
+ import { basename as basename3, resolve as resolve11 } from "path";
13351
13489
  var object6 = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
13352
13490
  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.");
13353
13491
  async function listCodexSessions(prepared, cwd, query) {
@@ -13362,11 +13500,11 @@ async function listCodexSessions(prepared, cwd, query) {
13362
13500
  let done = false, initialized = false, pending = Buffer.alloc(0), responseBytes = 0;
13363
13501
  let killTimer;
13364
13502
  let resolvePage, rejectPage;
13365
- const result = new Promise((resolve11, reject2) => {
13366
- resolvePage = resolve11;
13503
+ const result = new Promise((resolve12, reject2) => {
13504
+ resolvePage = resolve12;
13367
13505
  rejectPage = reject2;
13368
13506
  });
13369
- const closed = new Promise((resolve11) => child.once("close", () => resolve11()));
13507
+ const closed = new Promise((resolve12) => child.once("close", () => resolve12()));
13370
13508
  const stop = () => {
13371
13509
  child.stdin.destroy();
13372
13510
  child.kill("SIGTERM");
@@ -13465,16 +13603,16 @@ async function resolveCodexResumeArguments(prepared, nativeArgs, cwd, list = lis
13465
13603
  break;
13466
13604
  }
13467
13605
  if (nativeArgs[i].startsWith("--cd="))
13468
- effectiveCwd = resolve10(cwd, nativeArgs[i].slice(5));
13606
+ effectiveCwd = resolve11(cwd, nativeArgs[i].slice(5));
13469
13607
  else if (nativeArgs[i].startsWith("-C") && nativeArgs[i].length > 2)
13470
- effectiveCwd = resolve10(cwd, nativeArgs[i].slice(2));
13608
+ effectiveCwd = resolve11(cwd, nativeArgs[i].slice(2));
13471
13609
  if (codexOptionRequestsHelp(nativeArgs[i]))
13472
13610
  return nativeArgs;
13473
13611
  if (codexOptionTakesValue(nativeArgs[i])) {
13474
13612
  if (nativeArgs[i] === "--cd" || nativeArgs[i] === "-C") {
13475
13613
  if (!nativeArgs[i + 1])
13476
13614
  throw unavailable2();
13477
- effectiveCwd = resolve10(cwd, nativeArgs[i + 1]);
13615
+ effectiveCwd = resolve11(cwd, nativeArgs[i + 1]);
13478
13616
  }
13479
13617
  i++;
13480
13618
  continue;
@@ -13549,9 +13687,9 @@ async function resolveCodexResumeArguments(prepared, nativeArgs, cwd, list = lis
13549
13687
  // src/launcher.ts
13550
13688
  var LATE_RUN_FINALIZATION_TIMEOUT_MS = 5000;
13551
13689
  async function writeOriCodexCatalog(stateDir, models) {
13552
- const path = join20(stateDir, "ori-codex-models.json");
13690
+ const path = join21(stateDir, "ori-codex-models.json");
13553
13691
  const nativeModels2 = models.filter(codingEligible).map((model3, index) => codexModel(model3, index));
13554
- await writeFile17(path, JSON.stringify({ models: nativeModels2 }, null, 2) + `
13692
+ await writeFile18(path, JSON.stringify({ models: nativeModels2 }, null, 2) + `
13555
13693
  `, { mode: 384, flag: "wx" });
13556
13694
  return path;
13557
13695
  }
@@ -13589,7 +13727,7 @@ async function oriRequestForPlan(plan, options = {}) {
13589
13727
  throw new Error("Grok API-key authentication is disabled by GROK_DISABLE_API_KEY_AUTH. This provider launch cannot proceed under that native authentication policy.");
13590
13728
  if (plan.profile.harness === "grok" && policyEnvironment.GROK_FORCE_LOGIN_TEAM_ID?.trim())
13591
13729
  throw new Error("Grok requires a native team login through GROK_FORCE_LOGIN_TEAM_ID. This provider launch cannot proceed under that native authentication policy.");
13592
- const contract = await inspectOri({ executable: options.oriExecutable, cwd: options.cwd ? resolve11(options.cwd) : undefined });
13730
+ const contract = await inspectOri({ executable: options.oriExecutable, cwd: options.cwd ? resolve12(options.cwd) : undefined });
13593
13731
  const native = requireOriHarness(contract, target);
13594
13732
  if (!native.path)
13595
13733
  throw new Error("Ori did not report the native harness executable path.");
@@ -13637,15 +13775,15 @@ async function prepareOriForPlan(plan, options) {
13637
13775
  executable: detection.executable,
13638
13776
  version: detection.version,
13639
13777
  stateDir: options.stateDir,
13640
- cwd: resolve11(options.cwd ?? process.cwd()),
13778
+ cwd: resolve12(options.cwd ?? process.cwd()),
13641
13779
  args: options.args ?? [],
13642
13780
  sharedState: options.sharedState
13643
13781
  });
13644
13782
  try {
13645
13783
  const shim = prepareOriModelPolicy(request.target, native);
13646
- const dir = join20(options.stateDir, "ori-bin"), path = join20(dir, shim.name);
13784
+ const dir = join21(options.stateDir, "ori-bin"), path = join21(dir, shim.name);
13647
13785
  await mkdir12(dir, { mode: 448 });
13648
- await writeFile17(path, shim.script, { mode: 448, flag: "wx" });
13786
+ await writeFile18(path, shim.script, { mode: 448, flag: "wx" });
13649
13787
  return { contract, prepared: {
13650
13788
  ...ori,
13651
13789
  env: { ...ori.env, ...shim.env, PATH: `${dir}:${ori.env.PATH ?? process.env.PATH ?? ""}` },
@@ -13660,6 +13798,8 @@ async function prepareOriForPlan(plan, options) {
13660
13798
  }
13661
13799
  }
13662
13800
  async function launch(client, profileId, options = {}) {
13801
+ if (options.backend === "ori" && options.shareNativeState === false)
13802
+ throw new Fault(400, "native_state_backend", "Explicit native-state isolation requires the direct adapter; Ori isolation is not yet verified.");
13663
13803
  const launchDeadline = options.timeoutMs === undefined ? undefined : Date.now() + options.timeoutMs;
13664
13804
  const profile = await client.getProfile(profileId);
13665
13805
  if ((options.reasoning || options.dangerouslyBypassApprovalsAndSandbox) && (profile.harness !== "codex" || (options.backend ?? "direct") !== "direct"))
@@ -13667,7 +13807,7 @@ async function launch(client, profileId, options = {}) {
13667
13807
  assertHarnessArguments(profile.harness, options.args ?? []);
13668
13808
  if (profile.harness === "gemini" || profile.harness === "antigravity")
13669
13809
  validateHarnessProvider(profile.harness, await client.getProvider(profile.providerId));
13670
- await validateHarnessConfiguration(profile.harness, resolve11(options.cwd ?? process.cwd()), options.args);
13810
+ await validateHarnessConfiguration(profile.harness, resolve12(options.cwd ?? process.cwd()), options.args);
13671
13811
  if (profile.harness === "grok" && !["", "0", "false", "no", "off"].includes((process.env.GROK_DISABLE_API_KEY_AUTH ?? "").trim().toLowerCase()))
13672
13812
  throw new Error("Grok API-key authentication is disabled by GROK_DISABLE_API_KEY_AUTH. This provider launch cannot proceed under that native authentication policy.");
13673
13813
  if (profile.harness === "grok" && process.env.GROK_FORCE_LOGIN_TEAM_ID?.trim())
@@ -13676,7 +13816,7 @@ async function launch(client, profileId, options = {}) {
13676
13816
  await client.refreshModels(profile.providerId);
13677
13817
  const plan = await client.launchPlan(profileId);
13678
13818
  assertHarnessArguments(plan.profile.harness, options.args ?? []);
13679
- await validateHarnessConfiguration(plan.profile.harness, resolve11(options.cwd ?? process.cwd()), options.args);
13819
+ await validateHarnessConfiguration(plan.profile.harness, resolve12(options.cwd ?? process.cwd()), options.args);
13680
13820
  if (options.credentialPreflight && providerCredentialFingerprint(plan.provider) !== options.credentialPreflight)
13681
13821
  throw new Fault(409, "credential_preflight_changed", "The provider authority or credential contract changed after authentication. Retry the launch; no credential was sent.");
13682
13822
  const backend = options.backend ?? "direct";
@@ -13698,9 +13838,9 @@ async function launch(client, profileId, options = {}) {
13698
13838
  validateHarnessVersion("gemini", detection?.version);
13699
13839
  if (backend === "direct" && plan.profile.harness === "aider")
13700
13840
  validateHarnessVersion(plan.profile.harness, detection?.version);
13701
- const root = resolve11(options.stateDir ?? join20(switcherHome(), "state"));
13841
+ const root = resolve12(options.stateDir ?? join21(switcherHome(), "state"));
13702
13842
  await privateDirectory(root);
13703
- const stateDir = await mkdtemp(join20(root, "launch-"));
13843
+ const stateDir = await mkdtemp(join21(root, "launch-"));
13704
13844
  let credential;
13705
13845
  if (backend === "direct") {
13706
13846
  try {
@@ -13744,27 +13884,42 @@ async function launch(client, profileId, options = {}) {
13744
13884
  return;
13745
13885
  });
13746
13886
  try {
13747
- if (options.shareNativeState && plan.profile.harness !== "codex" && plan.profile.harness !== "claude")
13748
- throw new Fault(400, "native_state_harness", "--share-native-state is supported only for Codex, ChatGPT, Claude CLI and Claude desktop launches.");
13749
- const shareRequested = (plan.profile.harness === "codex" || plan.profile.harness === "claude") && nativeStateRequested(plan.profile.harness, process.env, Boolean(options.shareNativeState));
13887
+ if (options.shareNativeState !== undefined && plan.profile.harness !== "codex" && plan.profile.harness !== "claude")
13888
+ throw new Fault(400, "native_state_harness", "Native-state options are supported only for Codex, ChatGPT, Claude CLI and Claude desktop launches.");
13889
+ const shareRequested = (plan.profile.harness === "codex" || plan.profile.harness === "claude") && nativeStateRequested(plan.profile.harness, process.env, options.shareNativeState);
13750
13890
  if (shareRequested && backend !== "direct")
13751
13891
  throw new Fault(400, "native_state_backend", "Shared native state currently requires the directly verified native adapter; Ori state/resume integration is not yet accepted.");
13752
- if (shareRequested && plan.profile.harness === "codex") {
13892
+ if ((shareRequested || options.shareNativeState === false) && plan.profile.harness === "codex")
13753
13893
  assertHarnessArguments("codex", options.args ?? [], { reservedCodexRoots: ["sqlite_home"] });
13894
+ if (shareRequested && plan.profile.harness === "codex")
13754
13895
  validateNativeStateVersion("codex", detection?.version);
13755
- }
13756
13896
  const sharedState = shareRequested ? await resolveNativeState(plan.profile.harness) : undefined;
13757
13897
  const desktopState = profileId;
13758
- const stateWarnings = sharedState ? ["Shared native state is explicitly enabled. Resumed conversation history uses this launch's selected provider and model; Switcher does not infer unverified original-provider provenance.", ...await legacyNativeStateWarnings(root, sharedState)] : [];
13898
+ const stateWarnings = sharedState ? ["Shared native state is enabled. Resumed conversation history uses this launch's selected provider and model; Switcher does not infer unverified original-provider provenance.", ...await legacyNativeStateWarnings(root, sharedState)] : [];
13759
13899
  let nativeHome2;
13760
13900
  if (sharedState && !options.desktop && !options.claudeDesktop) {
13761
13901
  const variable = sharedState.tool === "codex" ? "CODEX_HOME" : "CLAUDE_CONFIG_DIR";
13762
- const configured = process.env[variable] ? resolve11(process.env[variable]) : undefined;
13763
- nativeHome2 = sharedState.tool === "claude" && (!configured || configured === sharedState.home) ? join20(root, "native-claude", profileId) : configured ?? sharedState.home;
13902
+ const configured = process.env[variable] ? resolve12(process.env[variable]) : undefined;
13903
+ nativeHome2 = sharedState.tool === "claude" && (!configured || configured === sharedState.home) ? join21(root, "native-claude", profileId) : configured ?? sharedState.home;
13904
+ if (sharedState.tool === "claude")
13905
+ await prepareClaudeUserSettings(nativeHome2);
13764
13906
  await privateDirectory(nativeHome2);
13765
13907
  await assertNativeInstructionOverlay(sharedState, nativeHome2);
13766
13908
  await projectNativeState(sharedState, nativeHome2);
13767
13909
  }
13910
+ if (options.shareNativeState === false && backend === "direct") {
13911
+ const tool = plan.profile.harness;
13912
+ if (options.desktop)
13913
+ await assertNativeStateIsolation(tool, join21(root, "desktop", desktopState, "codex"));
13914
+ else if (options.claudeDesktop)
13915
+ await assertNativeStateIsolation(tool, join21(root, "desktop-claude", desktopState));
13916
+ else {
13917
+ const variable = tool === "codex" ? "CODEX_HOME" : "CLAUDE_CONFIG_DIR";
13918
+ nativeHome2 = process.env[variable] ? resolve12(process.env[variable]) : join21(root, `native-${tool}`, profileId);
13919
+ await assertNativeStateIsolation(tool, nativeHome2);
13920
+ await privateDirectory(nativeHome2);
13921
+ }
13922
+ }
13768
13923
  const input = {
13769
13924
  harness: plan.profile.harness,
13770
13925
  baseUrl: plan.provider.baseUrl,
@@ -13777,10 +13932,10 @@ async function launch(client, profileId, options = {}) {
13777
13932
  onRoutingEvent,
13778
13933
  credential,
13779
13934
  stateDir,
13780
- cwd: resolve11(options.cwd ?? process.cwd()),
13935
+ cwd: resolve12(options.cwd ?? process.cwd()),
13781
13936
  sharedState
13782
13937
  };
13783
- let prepared = options.claudeDesktop ? await prepareClaudeDesktopLaunch(input, options.claudeDesktop, join20(root, "desktop-claude", desktopState)) : backend === "ori" ? (await prepareOriForPlan(plan, { ...options, stateDir, onRoutingEvent, sharedState })).prepared : await prepareHarnessLaunch({
13938
+ let prepared = options.claudeDesktop ? await prepareClaudeDesktopLaunch(input, options.claudeDesktop, join21(root, "desktop-claude", desktopState)) : backend === "ori" ? (await prepareOriForPlan(plan, { ...options, stateDir, onRoutingEvent, sharedState })).prepared : await prepareHarnessLaunch({
13784
13939
  harness: plan.profile.harness,
13785
13940
  baseUrl: plan.provider.baseUrl,
13786
13941
  protocol: plan.provider.protocol,
@@ -13796,18 +13951,19 @@ async function launch(client, profileId, options = {}) {
13796
13951
  executable: nativeExecutable ?? detection?.executable,
13797
13952
  args: options.args ?? [],
13798
13953
  stateDir,
13799
- cwd: resolve11(options.cwd ?? process.cwd()),
13954
+ cwd: resolve12(options.cwd ?? process.cwd()),
13800
13955
  version: detection?.version,
13801
13956
  sharedState,
13802
- ...["pi", "omp", "dsh", "cline", "hermes", "prime-agent", "gemini", "aider", "opencode", "kilo", "antigravity", "junie"].includes(plan.profile.harness) ? { sessionDir: join20(root, "sessions", plan.profile.harness, profileId) } : {}
13957
+ ...["pi", "omp", "dsh", "cline", "hermes", "prime-agent", "gemini", "aider", "opencode", "kilo", "antigravity", "junie"].includes(plan.profile.harness) ? { sessionDir: join21(root, "sessions", plan.profile.harness, profileId) } : {}
13803
13958
  });
13804
13959
  cleanup = prepared.cleanup;
13805
13960
  prepared = { ...prepared, warnings: [...prepared.warnings, ...stateWarnings] };
13806
- if (sharedState)
13961
+ if (sharedState || nativeHome2)
13807
13962
  prepared = { ...prepared, env: {
13808
13963
  ...prepared.env,
13809
- ...nativeStateEnvironment(sharedState),
13810
- ...nativeHome2 ? { [sharedState.tool === "codex" ? "CODEX_HOME" : "CLAUDE_CONFIG_DIR"]: nativeHome2 } : {}
13964
+ ...sharedState ? nativeStateEnvironment(sharedState) : {},
13965
+ ...nativeHome2 ? { [plan.profile.harness === "codex" ? "CODEX_HOME" : "CLAUDE_CONFIG_DIR"]: nativeHome2 } : {},
13966
+ ...nativeHome2 && options.shareNativeState === false && plan.profile.harness === "codex" ? { CODEX_SQLITE_HOME: nativeHome2 } : {}
13811
13967
  } };
13812
13968
  if (sharedState?.tool === "codex" && !options.desktop && backend === "direct" && options.args?.length) {
13813
13969
  const baseArgs = prepared.args.slice(0, prepared.args.length - options.args.length);
@@ -13815,7 +13971,7 @@ async function launch(client, profileId, options = {}) {
13815
13971
  prepared = { ...prepared, args: [...baseArgs, ...resumedArgs] };
13816
13972
  }
13817
13973
  if (options.desktop) {
13818
- prepared = await prepareChatGPTLaunch(prepared, options.desktop, stateDir, join20(root, "desktop", desktopState), sharedState);
13974
+ prepared = await prepareChatGPTLaunch(prepared, options.desktop, stateDir, join21(root, "desktop", desktopState), sharedState);
13819
13975
  cleanup = prepared.cleanup;
13820
13976
  }
13821
13977
  for (const warning of [...plan.warnings, ...prepared.warnings])
@@ -13892,7 +14048,7 @@ async function launch(client, profileId, options = {}) {
13892
14048
  interruptPreparation(new CommandInterrupted(143, "Launch timed out before the native harness started."), false);
13893
14049
  throw preparationSignal;
13894
14050
  }
13895
- const { code, interrupted } = await runHarnessProcess({ executable: prepared.executable, args: prepared.args, cwd: resolve11(options.cwd ?? process.cwd()), env: { ...childEnvironment(), ...prepared.env }, silent: Boolean(options.desktop || options.claudeDesktop), timeoutMs: remainingRuntime });
14051
+ const { code, interrupted } = await runHarnessProcess({ executable: prepared.executable, args: prepared.args, cwd: resolve12(options.cwd ?? process.cwd()), env: { ...childEnvironment(), ...prepared.env }, silent: Boolean(options.desktop || options.claudeDesktop), timeoutMs: remainingRuntime });
13896
14052
  await cleanup?.();
13897
14053
  cleanup = undefined;
13898
14054
  await finishRunOnce(run, { status: interrupted ? "interrupted" : code === 0 ? "exited" : "failed", exitCode: code }, `switcher: Harness exited ${code}; final metadata could not be saved for run ${run.id}.`);
@@ -13909,8 +14065,8 @@ async function launch(client, profileId, options = {}) {
13909
14065
  } finally {
13910
14066
  if (lateCreateRunFinalization) {
13911
14067
  let finalizationTimer;
13912
- const finalizationTimeout = new Promise((resolve12) => {
13913
- finalizationTimer = setTimeout(resolve12, LATE_RUN_FINALIZATION_TIMEOUT_MS);
14068
+ const finalizationTimeout = new Promise((resolve13) => {
14069
+ finalizationTimer = setTimeout(resolve13, LATE_RUN_FINALIZATION_TIMEOUT_MS);
13914
14070
  });
13915
14071
  try {
13916
14072
  await Promise.race([lateCreateRunFinalization, finalizationTimeout]);
@@ -14035,15 +14191,15 @@ async function ensureLaunchProfile(client, provider, harness, model3, modelPolic
14035
14191
 
14036
14192
  // src/native-state-import.ts
14037
14193
  import { createHash as createHash15 } from "crypto";
14038
- import { constants as constants8 } from "fs";
14039
- import { lstat as lstat9, open as open5, opendir as opendir2, link as link2, rmdir as rmdir2, unlink as unlink3 } from "fs/promises";
14040
- import { basename as basename4, dirname as dirname9, isAbsolute as isAbsolute17, join as join21, relative as relative6, resolve as resolve12 } from "path";
14194
+ import { constants as constants9 } from "fs";
14195
+ import { lstat as lstat10, open as open6, opendir as opendir2, link as link2, rmdir as rmdir2, unlink as unlink3 } from "fs/promises";
14196
+ import { basename as basename4, dirname as dirname9, isAbsolute as isAbsolute17, join as join22, relative as relative6, resolve as resolve13 } from "path";
14041
14197
  var MAX_FILES = 1e5;
14042
14198
  var MAX_BYTES2 = 2 * 1024 * 1024 * 1024;
14043
14199
  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.");
14044
14200
  async function info2(path) {
14045
14201
  try {
14046
- return await lstat9(path);
14202
+ return await lstat10(path);
14047
14203
  } catch (error) {
14048
14204
  if (error.code === "ENOENT")
14049
14205
  return;
@@ -14059,7 +14215,7 @@ var inside3 = (parent, child) => {
14059
14215
  var SESSION_ID = /^[a-f\d]{8}(?:-[a-f\d]{4}){3}-[a-f\d]{12}$/i;
14060
14216
  async function sessionId(path, expected) {
14061
14217
  const nameId = basename4(path).match(/([a-f\d]{8}(?:-[a-f\d]{4}){3}-[a-f\d]{12})\.jsonl$/i)?.[1]?.toLowerCase();
14062
- const handle = await open5(path, constants8.O_RDONLY | constants8.O_NOFOLLOW);
14218
+ const handle = await open6(path, constants9.O_RDONLY | constants9.O_NOFOLLOW);
14063
14219
  try {
14064
14220
  const before = await handle.stat();
14065
14221
  if (!before.isFile() || before.nlink !== 1 || before.uid !== process.getuid?.() || before.mode & 18 || expected && !same(before, expected))
@@ -14073,7 +14229,7 @@ async function sessionId(path, expected) {
14073
14229
  length += read.bytesRead;
14074
14230
  newline = buffer.indexOf(10, 0);
14075
14231
  }
14076
- const after = await handle.stat(), named = await lstat9(path);
14232
+ const after = await handle.stat(), named = await lstat10(path);
14077
14233
  if (!same(before, after) || !same(after, named) || after.nlink !== 1 || named.nlink !== 1 || named.isSymbolicLink())
14078
14234
  throw refused();
14079
14235
  if (newline < 0 && before.size > buffer.length)
@@ -14102,7 +14258,7 @@ async function checkSessionIdentities(plan) {
14102
14258
  for (const file of plan.files) {
14103
14259
  if (!/^(sessions|archived_sessions)\//.test(file.path) || !file.path.endsWith(".jsonl"))
14104
14260
  continue;
14105
- file.sessionId = await sessionId(join21(plan.source, file.path), file.source);
14261
+ file.sessionId = await sessionId(join22(plan.source, file.path), file.source);
14106
14262
  if (!file.sessionId)
14107
14263
  continue;
14108
14264
  const previous = ids.get(file.sessionId);
@@ -14126,7 +14282,7 @@ async function checkSessionIdentities(plan) {
14126
14282
  for await (const entry of await opendir2(directory)) {
14127
14283
  if (++seen > MAX_FILES || entry.isSymbolicLink())
14128
14284
  throw refused();
14129
- const path = join21(directory, entry.name);
14285
+ const path = join22(directory, entry.name);
14130
14286
  if (entry.isDirectory()) {
14131
14287
  await scan(path, depth + 1);
14132
14288
  continue;
@@ -14143,18 +14299,18 @@ async function checkSessionIdentities(plan) {
14143
14299
  file.existing = true;
14144
14300
  }
14145
14301
  }
14146
- await scan(join21(plan.state.home, "sessions"));
14147
- await scan(join21(plan.state.home, "archived_sessions"));
14302
+ await scan(join22(plan.state.home, "sessions"));
14303
+ await scan(join22(plan.state.home, "archived_sessions"));
14148
14304
  }
14149
14305
  async function fingerprint2(path, copyTo) {
14150
- const handle = await open5(path, constants8.O_RDONLY | constants8.O_NOFOLLOW);
14306
+ const handle = await open6(path, constants9.O_RDONLY | constants9.O_NOFOLLOW);
14151
14307
  let output, complete = false;
14152
14308
  try {
14153
14309
  const before = await handle.stat();
14154
14310
  if (!before.isFile() || before.nlink !== 1 || before.uid !== process.getuid?.() || before.mode & 18 || before.size > MAX_BYTES2)
14155
14311
  throw refused();
14156
14312
  if (copyTo)
14157
- output = await open5(copyTo, "wx", 384);
14313
+ output = await open6(copyTo, "wx", 384);
14158
14314
  const hash3 = createHash15("sha256"), buffer = Buffer.alloc(64 * 1024);
14159
14315
  let bytes = 0;
14160
14316
  for (;; ) {
@@ -14172,7 +14328,7 @@ async function fingerprint2(path, copyTo) {
14172
14328
  offset += (await output.write(chunk, offset, chunk.length - offset)).bytesWritten;
14173
14329
  }
14174
14330
  }
14175
- const after = await handle.stat(), named = await lstat9(path);
14331
+ const after = await handle.stat(), named = await lstat10(path);
14176
14332
  if (named.isSymbolicLink() || after.nlink !== 1 || named.nlink !== 1 || bytes !== before.size || !same(before, after) || !same(after, named))
14177
14333
  throw refused();
14178
14334
  await output?.sync();
@@ -14190,12 +14346,12 @@ async function fingerprint2(path, copyTo) {
14190
14346
  async function planNativeStateImport(state, source, selection) {
14191
14347
  if (!isAbsolute17(source) || source.includes("\x00"))
14192
14348
  throw refused();
14193
- source = resolve12(source);
14349
+ source = resolve13(source);
14194
14350
  if (inside3(source, state.home) || inside3(state.home, source))
14195
14351
  throw refused();
14196
14352
  await assertNativeStateDirectory(source);
14197
14353
  await ensureNativeStateDirectory(state.home, false);
14198
- const allowed = NATIVE_STATE_ENTRIES[state.tool].filter((entry) => entry.name !== "thread-writer-locks");
14354
+ const allowed = NATIVE_STATE_ENTRIES[state.tool].filter((entry) => !["thread-writer-locks", "skills"].includes(entry.name));
14199
14355
  const entries = selection?.length ? [...new Set(selection)] : allowed.map((entry) => entry.name);
14200
14356
  if (entries.some((name) => !allowed.some((entry) => entry.name === name)))
14201
14357
  throw refused();
@@ -14204,9 +14360,9 @@ async function planNativeStateImport(state, source, selection) {
14204
14360
  async function visit(path, kind) {
14205
14361
  if (++seen > MAX_FILES || path.split("/").length > 32)
14206
14362
  throw refused();
14207
- await ensureNativeStateDirectory(dirname9(join21(source, path)), false);
14208
- await ensureNativeStateDirectory(dirname9(join21(state.home, path)), false);
14209
- const from = join21(source, path), to = join21(state.home, path), entry = await info2(from), target = await info2(to);
14363
+ await ensureNativeStateDirectory(dirname9(join22(source, path)), false);
14364
+ await ensureNativeStateDirectory(dirname9(join22(state.home, path)), false);
14365
+ const from = join22(source, path), to = join22(state.home, path), entry = await info2(from), target = await info2(to);
14210
14366
  if (!entry)
14211
14367
  return;
14212
14368
  if (entry.isSymbolicLink() || entry.uid !== process.getuid?.() || entry.mode & 18 || (kind === "directory" ? !entry.isDirectory() : !entry.isFile()))
@@ -14225,7 +14381,7 @@ async function planNativeStateImport(state, source, selection) {
14225
14381
  }
14226
14382
  children.sort((a, b) => a.name.localeCompare(b.name));
14227
14383
  for (const child of children)
14228
- await visit(join21(path, child.name), child.kind);
14384
+ await visit(join22(path, child.name), child.kind);
14229
14385
  } else {
14230
14386
  const value = await fingerprint2(from);
14231
14387
  plan.bytes += value.bytes;
@@ -14279,14 +14435,14 @@ async function applyNativeStateImportUnlocked(plan) {
14279
14435
  throw refused();
14280
14436
  const requiredDirectories = new Set([plan.state.home]);
14281
14437
  for (const path of plan.directories) {
14282
- for (let directory = join21(plan.state.home, path);inside3(plan.state.home, directory); directory = dirname9(directory)) {
14438
+ for (let directory = join22(plan.state.home, path);inside3(plan.state.home, directory); directory = dirname9(directory)) {
14283
14439
  requiredDirectories.add(directory);
14284
14440
  if (directory === plan.state.home)
14285
14441
  break;
14286
14442
  }
14287
14443
  }
14288
14444
  for (const file of plan.files.filter((file2) => !file2.existing)) {
14289
- for (let directory = dirname9(join21(plan.state.home, file.path));inside3(plan.state.home, directory); directory = dirname9(directory)) {
14445
+ for (let directory = dirname9(join22(plan.state.home, file.path));inside3(plan.state.home, directory); directory = dirname9(directory)) {
14290
14446
  requiredDirectories.add(directory);
14291
14447
  if (directory === plan.state.home)
14292
14448
  break;
@@ -14307,9 +14463,9 @@ async function applyNativeStateImportUnlocked(plan) {
14307
14463
  for (const file of plan.files) {
14308
14464
  if (file.existing)
14309
14465
  continue;
14310
- const target = join21(plan.state.home, file.path), temporary = join21(dirname9(target), `.switcher-import-${crypto.randomUUID()}`);
14466
+ const target = join22(plan.state.home, file.path), temporary = join22(dirname9(target), `.switcher-import-${crypto.randomUUID()}`);
14311
14467
  staged.push({ temporary, target });
14312
- const copied = await fingerprint2(join21(plan.source, file.path), temporary);
14468
+ const copied = await fingerprint2(join22(plan.source, file.path), temporary);
14313
14469
  if (copied.bytes !== file.bytes || copied.sha256 !== file.sha256 || !same(copied.source, file.source))
14314
14470
  throw refused();
14315
14471
  }
@@ -14365,11 +14521,11 @@ async function applyNativeStateImport(plan) {
14365
14521
  var HELP = `switcher \u2014 launch coding harnesses and desktop apps with your provider and model
14366
14522
 
14367
14523
  switcher launch chatgpt --provider PROVIDER --model MODEL [--reasoning EFFORT]
14368
- [--dangerously-bypass-approvals-and-sandbox] [--share-native-state]
14524
+ [--dangerously-bypass-approvals-and-sandbox] [--share-native-state | --no-share-native-state]
14369
14525
  [--app-path /absolute/ChatGPT.app]
14370
14526
  [--dry-run] [--cwd DIR] [--timeout SECONDS]
14371
14527
  switcher launch claude-desktop --provider PROVIDER --model MODEL
14372
- [--share-native-state] [--app-path /absolute/Claude.app] [--dry-run]
14528
+ [--share-native-state | --no-share-native-state] [--app-path /absolute/Claude.app] [--dry-run]
14373
14529
  switcher providers presets [ID]
14374
14530
  switcher providers list [--search TEXT] [--limit N] [--offset N]
14375
14531
  switcher providers add ID --url URL --protocol PROTOCOL [--credential-env NAME]
@@ -14387,8 +14543,8 @@ var HELP = `switcher \u2014 launch coding harnesses and desktop apps with your p
14387
14543
  switcher profiles add ID --provider ID --harness HARNESS --model MODEL [--model-policy-file FILE] [--role-model ROLE=MODEL]
14388
14544
  switcher profiles update ID --file profile.json --version N
14389
14545
  switcher profiles delete ID --version N
14390
- switcher launch HARNESS --provider PROVIDER [--model MODEL] [--share-native-state] [--dry-run]
14391
- switcher launch PROFILE [--backend direct|ori] [--share-native-state] [--cwd DIR] [--executable PATH]
14546
+ switcher launch HARNESS --provider PROVIDER [--model MODEL] [--share-native-state | --no-share-native-state] [--dry-run]
14547
+ switcher launch PROFILE [--backend direct|ori] [--share-native-state | --no-share-native-state] [--cwd DIR] [--executable PATH]
14392
14548
  [--ori-executable PATH] [--state-dir DIR]
14393
14549
  [--timeout SECONDS] -- [native harness arguments]
14394
14550
  switcher runs list|get [ID]
@@ -14403,7 +14559,9 @@ var HELP = `switcher \u2014 launch coding harnesses and desktop apps with your p
14403
14559
 
14404
14560
  HARNESS: claude, codex, grok, opencode, opencode2, pi, omp, dsh, cline, hermes, prime-agent, gemini, antigravity, junie, aider, kilo
14405
14561
  chatgpt launches the installed macOS desktop app with private login data.
14406
- Use --share-native-state to project the canonical noncredential Codex/Claude corpus.
14562
+ Claude shares canonical sessions, skills and instructions by default.
14563
+ Use --no-share-native-state for isolation. Codex currently requires
14564
+ --share-native-state or a canonical state marker.
14407
14565
  Its local Codex conversations use the selected Responses-compatible provider.
14408
14566
  claude-desktop launches Claude in its separate Claude-3p gateway profile with a
14409
14567
  Messages-compatible provider. Quit that instance before switching providers.
@@ -14490,6 +14648,7 @@ async function main(args = process.argv.slice(2)) {
14490
14648
  reasoning: { type: "string" },
14491
14649
  "dangerously-bypass-approvals-and-sandbox": { type: "boolean" },
14492
14650
  "share-native-state": { type: "boolean" },
14651
+ "no-share-native-state": { type: "boolean" },
14493
14652
  from: { type: "string" },
14494
14653
  entry: { type: "string", multiple: true },
14495
14654
  apply: { type: "boolean" },
@@ -14553,16 +14712,19 @@ async function main(args = process.argv.slice(2)) {
14553
14712
  }
14554
14713
  if (values2.from !== undefined || values2.entry !== undefined || values2.apply !== undefined || values2["plan-digest"] !== undefined)
14555
14714
  throw new Fault(400, "conflicting_options", "--from, --entry, --plan-digest, --dry-run and --apply belong to switcher state import.");
14556
- if (values2["share-native-state"] && command !== "launch")
14557
- throw new Fault(400, "conflicting_options", "--share-native-state belongs to a Codex, ChatGPT, Claude CLI or Claude desktop launch.");
14715
+ if (values2["share-native-state"] && values2["no-share-native-state"])
14716
+ throw new Fault(400, "conflicting_options", "Use only one of --share-native-state and --no-share-native-state.");
14717
+ const shareNativeState = values2["no-share-native-state"] ? false : values2["share-native-state"];
14718
+ if (shareNativeState !== undefined && command !== "launch")
14719
+ throw new Fault(400, "conflicting_options", "--share-native-state and --no-share-native-state belong to a Codex, ChatGPT, Claude CLI or Claude desktop launch.");
14558
14720
  const reasoning = values2.reasoning === undefined ? undefined : parse2(reasoningEffortSchema, values2.reasoning);
14559
14721
  const dangerouslyBypassApprovalsAndSandbox = values2["dangerously-bypass-approvals-and-sandbox"];
14560
14722
  if ((reasoning || dangerouslyBypassApprovalsAndSandbox) && (command !== "launch" || values2.provider && !["chatgpt", "codex"].includes(action2) || values2.backend && values2.backend !== "direct"))
14561
14723
  throw new Fault(400, "conflicting_options", "--reasoning and --dangerously-bypass-approvals-and-sandbox require a direct Codex or ChatGPT launch.");
14562
14724
  const chatgpt = command === "launch" && action2 === "chatgpt" && values2.provider !== undefined;
14563
14725
  const claudeDesktop = command === "launch" && action2 === "claude-desktop" && values2.provider !== undefined;
14564
- if (values2["share-native-state"] && values2.provider !== undefined && !["codex", "claude", "chatgpt", "claude-desktop"].includes(action2))
14565
- throw new Fault(400, "native_state_harness", "--share-native-state is supported only for Codex, ChatGPT, Claude CLI and Claude desktop launches.");
14726
+ if (shareNativeState !== undefined && values2.provider !== undefined && !["codex", "claude", "chatgpt", "claude-desktop"].includes(action2))
14727
+ throw new Fault(400, "native_state_harness", "Native-state options are supported only for Codex, ChatGPT, Claude CLI and Claude desktop launches.");
14566
14728
  if (values2["app-path"] !== undefined && !chatgpt && !claudeDesktop)
14567
14729
  throw new Fault(400, "conflicting_options", "--app-path belongs to launch chatgpt or claude-desktop --provider PROVIDER --model MODEL.");
14568
14730
  if ((chatgpt || claudeDesktop) && (nativeArgs.length || positionals.length !== 2 || values2.executable !== undefined || values2.backend !== undefined || values2["ori-executable"] !== undefined))
@@ -14665,6 +14827,8 @@ async function main(args = process.argv.slice(2)) {
14665
14827
  const backend = values2.backend ?? "direct";
14666
14828
  if (backend !== "direct" && backend !== "ori")
14667
14829
  throw new Fault(400, "invalid_backend", "Use --backend direct or --backend ori.");
14830
+ if (command === "launch" && backend === "ori" && values2["no-share-native-state"])
14831
+ throw new Fault(400, "native_state_backend", "Explicit native-state isolation requires the direct adapter; Ori isolation is not yet verified.");
14668
14832
  if (command !== "launch" && (values2.backend !== undefined || values2["ori-executable"] !== undefined))
14669
14833
  throw new Fault(400, "conflicting_options", "--backend and --ori-executable belong to launch.");
14670
14834
  if (command === "launch" && backend === "ori" && values2.executable !== undefined)
@@ -14768,8 +14932,8 @@ async function main(args = process.argv.slice(2)) {
14768
14932
  if (values2.model || values2.protocol || values2.url || values2["credential-env"] || values2["model-policy-file"] || values2["role-model"])
14769
14933
  throw new Error("Use --provider PROVIDER for a direct launch, or update the saved profile explicitly.");
14770
14934
  const profile = await client.getProfile(profileId);
14771
- if (values2["share-native-state"] && !["codex", "claude"].includes(profile.harness))
14772
- throw new Fault(400, "native_state_harness", "--share-native-state is supported only for Codex, ChatGPT, Claude CLI and Claude desktop launches.");
14935
+ if (shareNativeState !== undefined && !["codex", "claude"].includes(profile.harness))
14936
+ throw new Fault(400, "native_state_harness", "Native-state options are supported only for Codex, ChatGPT, Claude CLI and Claude desktop launches.");
14773
14937
  assertHarnessArguments(profile.harness, nativeArgs);
14774
14938
  await validateHarnessConfiguration(profile.harness, values2.cwd ?? process.cwd(), nativeArgs);
14775
14939
  const provider = await client.getProvider(profile.providerId);
@@ -14796,24 +14960,32 @@ async function main(args = process.argv.slice(2)) {
14796
14960
  codexReasoning(model3, plan.provider.baseUrl, reasoning);
14797
14961
  }
14798
14962
  assertHarnessArguments(plan.profile.harness, nativeArgs);
14799
- if (values2["share-native-state"] && !["codex", "claude"].includes(plan.profile.harness))
14800
- throw new Fault(400, "native_state_harness", "--share-native-state is supported only for Codex, ChatGPT, Claude CLI and Claude desktop launches.");
14801
- const sharedNativeState = ["codex", "claude"].includes(plan.profile.harness) && nativeStateRequested(plan.profile.harness, process.env, Boolean(values2["share-native-state"]));
14802
- if (sharedNativeState) {
14803
- if (plan.profile.harness === "codex")
14804
- assertHarnessArguments("codex", nativeArgs, { reservedCodexRoots: ["sqlite_home"] });
14963
+ if (shareNativeState !== undefined && !["codex", "claude"].includes(plan.profile.harness))
14964
+ throw new Fault(400, "native_state_harness", "Native-state options are supported only for Codex, ChatGPT, Claude CLI and Claude desktop launches.");
14965
+ const sharedNativeState = ["codex", "claude"].includes(plan.profile.harness) && nativeStateRequested(plan.profile.harness, process.env, shareNativeState);
14966
+ const suffix = plan.profile.harness.toUpperCase();
14967
+ const marked = process.env[`HASNA_${suffix}_STATE_HOME`] !== undefined || process.env[`SUBSCRIPTIONS_SHARED_HOME_${suffix}`] !== undefined;
14968
+ const nativeState = sharedNativeState ? { shared: true, consent: shareNativeState === true ? "command" : marked ? "environment" : "default" } : shareNativeState === false ? { shared: false, consent: "command" } : undefined;
14969
+ if ((sharedNativeState || shareNativeState === false) && plan.profile.harness === "codex")
14970
+ assertHarnessArguments("codex", nativeArgs, { reservedCodexRoots: ["sqlite_home"] });
14971
+ if (sharedNativeState)
14805
14972
  await resolveNativeState(plan.profile.harness, process.env, { create: false });
14973
+ if (shareNativeState === false) {
14974
+ const tool = plan.profile.harness, root = resolve14(values2["state-dir"] ?? join23(switcherHome(), "state"));
14975
+ const configured = process.env[tool === "codex" ? "CODEX_HOME" : "CLAUDE_CONFIG_DIR"];
14976
+ const home = desktop ? join23(root, "desktop", profileId, "codex") : claudeApp ? join23(root, "desktop-claude", profileId) : configured ? resolve14(configured) : join23(root, `native-${tool}`, profileId);
14977
+ await assertNativeStateIsolation(tool, home);
14806
14978
  }
14807
14979
  if (backend === "ori") {
14808
14980
  if (sharedNativeState)
14809
14981
  throw new Fault(400, "native_state_backend", "Shared native state currently requires the directly verified native adapter; Ori state/resume integration is not yet accepted.");
14810
14982
  const { contract, warnings } = await validateOriForPlan(plan, { oriExecutable: values2["ori-executable"], args: nativeArgs, cwd: values2.cwd });
14811
- output({ ...plan, backend: { kind: "ori", executable: contract.executable, version: contract.version, target: plan.profile.harness, provider: "openrouter", model: plan.profile.model, warnings: [...plan.warnings, ...warnings] }, ...sharedNativeState ? { nativeState: { shared: true, consent: values2["share-native-state"] ? "command" : "environment" } } : {} });
14983
+ output({ ...plan, backend: { kind: "ori", executable: contract.executable, version: contract.version, target: plan.profile.harness, provider: "openrouter", model: plan.profile.model, warnings: [...plan.warnings, ...warnings] }, ...nativeState ? { nativeState } : {} });
14812
14984
  } else
14813
- output({ ...plan, ...desktop ? { desktop: { ...desktop, mode: sharedNativeState ? "shared-state-private-auth" : "isolated-provider", sessionProfile: profileId, ...sharedNativeState ? { sessionIdentity: "canonical-native-corpus" } : {} } } : {}, ...claudeApp ? { desktop: { ...claudeApp, mode: "claude-3p-gateway", sessionProfile: profileId, ...sharedNativeState ? { sessionIdentity: "canonical-native-corpus" } : {} } } : {}, ...sharedNativeState ? { nativeState: { shared: true, consent: values2["share-native-state"] ? "command" : "environment" } } : {}, ...reasoning ? { reasoning } : {}, ...dangerouslyBypassApprovalsAndSandbox ? { permissions: { approvalPolicy: "never", sandboxMode: "danger-full-access" } } : {} });
14985
+ output({ ...plan, ...desktop ? { desktop: { ...desktop, mode: sharedNativeState ? "shared-state-private-auth" : "isolated-provider", sessionProfile: profileId, ...sharedNativeState ? { sessionIdentity: "canonical-native-corpus" } : {} } } : {}, ...claudeApp ? { desktop: { ...claudeApp, mode: "claude-3p-gateway", sessionProfile: profileId, ...sharedNativeState ? { sessionIdentity: "canonical-native-corpus" } : {} } } : {}, ...nativeState ? { nativeState } : {}, ...reasoning ? { reasoning } : {}, ...dangerouslyBypassApprovalsAndSandbox ? { permissions: { approvalPolicy: "never", sandboxMode: "danger-full-access" } } : {} });
14814
14986
  return;
14815
14987
  }
14816
- process.exitCode = await launch(client, profileId, { desktop, claudeDesktop: claudeApp, shareNativeState: Boolean(values2["share-native-state"]), reasoning, dangerouslyBypassApprovalsAndSandbox, backend, oriExecutable: values2["ori-executable"], cwd: values2.cwd, executable: values2.executable, stateDir: values2["state-dir"], args: nativeArgs, timeoutMs, refresh: false, credentialPreflight, resolveCredential: resolvePreparedCredential ?? ((provider) => credentials.resolve(provider)) });
14988
+ process.exitCode = await launch(client, profileId, { desktop, claudeDesktop: claudeApp, shareNativeState, reasoning, dangerouslyBypassApprovalsAndSandbox, backend, oriExecutable: values2["ori-executable"], cwd: values2.cwd, executable: values2.executable, stateDir: values2["state-dir"], args: nativeArgs, timeoutMs, refresh: false, credentialPreflight, resolveCredential: resolvePreparedCredential ?? ((provider) => credentials.resolve(provider)) });
14817
14989
  return;
14818
14990
  }
14819
14991
  if (editingModel) {
package/dist/index.js CHANGED
@@ -432,9 +432,14 @@ async function detectChatGPTApp(appPath, system = host) {
432
432
  const name = await field("CFBundleExecutable"), version2 = await field("CFBundleShortVersionString");
433
433
  if (!/^[A-Za-z0-9 _-]+$/.test(name))
434
434
  continue;
435
- const executable = join(path, "Contents/MacOS", name), codexExecutable = join(path, "Contents/Resources/codex");
436
- if (await system.executable(executable) && await system.executable(codexExecutable))
437
- return { path, executable, codexExecutable, bundleId, version: version2 };
435
+ const executable = join(path, "Contents/MacOS", name);
436
+ if (!await system.executable(executable))
437
+ continue;
438
+ for (const relative of ["Contents/Resources/codex", "Contents/Resources/codex-cli/CodexCLI.app/Contents/MacOS/codex"]) {
439
+ const codexExecutable = join(path, relative);
440
+ if (await system.executable(codexExecutable))
441
+ return { path, executable, codexExecutable, bundleId, version: version2 };
442
+ }
438
443
  } catch {}
439
444
  }
440
445
  throw new Fault(404, "app_not_installed", "Install the current ChatGPT/Codex macOS app or use --app-path with its absolute .app path. Legacy ChatGPT Classic cannot run custom Codex providers.");
package/dist/mcp/index.js CHANGED
@@ -69,7 +69,7 @@ function canonicalPolicyJSON(value) {
69
69
  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);
70
70
  }
71
71
  // package.json
72
- var version = "0.2.10";
72
+ var version = "0.2.11";
73
73
 
74
74
  // src/version.ts
75
75
  var VERSION = version;
@@ -1197,7 +1197,7 @@ var openapi_default = {
1197
1197
  openapi: "3.0.3",
1198
1198
  info: {
1199
1199
  title: "Switcher API",
1200
- version: "0.2.10",
1200
+ version: "0.2.11",
1201
1201
  description: "Authenticated provider/profile/catalog control plane. Launches run locally; the API never returns provider credentials."
1202
1202
  },
1203
1203
  security: [
@@ -16,6 +16,9 @@ type Entry = {
16
16
  export declare const NATIVE_STATE_ENTRIES: Record<SharedNativeTool, readonly Entry[]>;
17
17
  export declare function assertNativeStateDirectory(path: string): Promise<void>;
18
18
  export declare function ensureNativeStateDirectory(path: string, create?: boolean): Promise<void>;
19
+ /** Disabling projection must not silently reuse a previously shared overlay.
20
+ * Keep existing links intact; a different isolated profile is an explicit choice. */
21
+ export declare function assertNativeStateIsolation(tool: SharedNativeTool, home: string, environment?: NodeJS.ProcessEnv): Promise<void>;
19
22
  export declare function withNativeStateLock<T>(state: NativeState, operation: () => Promise<T>): Promise<T>;
20
23
  /** A nested CLI keeps its authentication home. Refuse conflicting instruction
21
24
  * overlays rather than rewriting account config or exposing instructions in argv. */
package/dist/sdk.js CHANGED
@@ -432,9 +432,14 @@ async function detectChatGPTApp(appPath, system = host) {
432
432
  const name = await field("CFBundleExecutable"), version2 = await field("CFBundleShortVersionString");
433
433
  if (!/^[A-Za-z0-9 _-]+$/.test(name))
434
434
  continue;
435
- const executable = join(path, "Contents/MacOS", name), codexExecutable = join(path, "Contents/Resources/codex");
436
- if (await system.executable(executable) && await system.executable(codexExecutable))
437
- return { path, executable, codexExecutable, bundleId, version: version2 };
435
+ const executable = join(path, "Contents/MacOS", name);
436
+ if (!await system.executable(executable))
437
+ continue;
438
+ for (const relative of ["Contents/Resources/codex", "Contents/Resources/codex-cli/CodexCLI.app/Contents/MacOS/codex"]) {
439
+ const codexExecutable = join(path, relative);
440
+ if (await system.executable(codexExecutable))
441
+ return { path, executable, codexExecutable, bundleId, version: version2 };
442
+ }
438
443
  } catch {}
439
444
  }
440
445
  throw new Fault(404, "app_not_installed", "Install the current ChatGPT/Codex macOS app or use --app-path with its absolute .app path. Legacy ChatGPT Classic cannot run custom Codex providers.");
@@ -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.10";
71
+ var version = "0.2.11";
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.10",
925
+ version: "0.2.11",
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.0",
7
+ "kitVersion": "1.3.3",
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.10",
5
+ "version": "0.2.11",
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.10",
3
+ "version": "0.2.11",
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",
@@ -72,7 +72,7 @@
72
72
  "@types/pg": "8.23.1"
73
73
  },
74
74
  "dependencies": {
75
- "@hasna/contracts": "1.3.0",
75
+ "@hasna/contracts": "1.3.3",
76
76
  "@modelcontextprotocol/sdk": "^1.29.0",
77
77
  "jsonc-parser": "3.3.1",
78
78
  "yaml": "2.9.0",