@hasna/switcher 0.2.19 → 0.2.20

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.
@@ -4,5 +4,10 @@ export declare function routingOrCredentialEnvironmentKey(key: string): boolean;
4
4
  * launches. No symlink, overwrite, credential migration or precedence change.
5
5
  * An explicit CLAUDE_CONFIG_DIR stays the settings source. Otherwise the
6
6
  * source is the corpus resolveNativeState selected (its real path), so a
7
- * ~/.claude symlink is never read through. */
8
- export declare function prepareClaudeUserSettings(overlayHome: string, environment?: NodeJS.ProcessEnv, corpusHome?: string): Promise<string[]>;
7
+ * ~/.claude symlink is never read through. With write false it makes the
8
+ * same refusals and returns the same warnings, and writes nothing; created
9
+ * names a missing folder the launch creates first (its state root). */
10
+ export declare function prepareClaudeUserSettings(overlayHome: string, environment?: NodeJS.ProcessEnv, corpusHome?: string, options?: {
11
+ write?: boolean;
12
+ created?: string;
13
+ }): Promise<string[]>;
package/dist/cli/index.js CHANGED
@@ -514,7 +514,7 @@ function canonicalPolicyJSON(value) {
514
514
  return JSON.stringify(value, (_key, item) => item && typeof item === "object" && !Array.isArray(item) ? Object.fromEntries(Object.entries(item).sort(([a], [b]) => a.localeCompare(b))) : item);
515
515
  }
516
516
  // package.json
517
- var version = "0.2.19";
517
+ var version = "0.2.20";
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.19",
2573
+ version: "0.2.20",
2574
2574
  description: "Authenticated provider/profile/catalog control plane. Launches run locally; the API never returns provider credentials."
2575
2575
  },
2576
2576
  security: [
@@ -7199,7 +7199,18 @@ function announceSwitcherLocalMode(home, write = (line) => {
7199
7199
  import { mkdir as mkdir4, lstat } from "fs/promises";
7200
7200
  async function privateDirectory(path) {
7201
7201
  await mkdir4(path, { recursive: true, mode: 448 });
7202
- const info = await lstat(path);
7202
+ assertPrivateEntry(await lstat(path));
7203
+ }
7204
+ async function checkPrivateDirectory(path) {
7205
+ const info = await lstat(path).catch((error) => {
7206
+ if (error.code === "ENOENT")
7207
+ return;
7208
+ throw error;
7209
+ });
7210
+ if (info)
7211
+ assertPrivateEntry(info);
7212
+ }
7213
+ function assertPrivateEntry(info) {
7203
7214
  if (!info.isDirectory() || info.isSymbolicLink())
7204
7215
  throw new Fault(500, "home_permissions", "Switcher data directory must be a real directory.");
7205
7216
  if (process.platform !== "win32" && ((info.mode & 63) !== 0 || info.uid !== process.getuid?.()))
@@ -10406,6 +10417,9 @@ async function jsonFile(dir, name, value) {
10406
10417
  `, { mode: 384, flag: "wx" });
10407
10418
  return path;
10408
10419
  }
10420
+ function claudeSettingsDirectory(sessionDir) {
10421
+ return join15(sessionDir, "settings");
10422
+ }
10409
10423
  async function durableJsonFile(dir, prefix, value) {
10410
10424
  const text = JSON.stringify(value, null, 2) + `
10411
10425
  `;
@@ -11105,7 +11119,7 @@ async function prepareNativeLaunch(input, providerBaseUrl = input.providerBaseUr
11105
11119
  env.ANTHROPIC_AUTH_TOKEN = "";
11106
11120
  env[input.authStyle === "x-api-key" ? "ANTHROPIC_API_KEY" : "ANTHROPIC_AUTH_TOKEN"] = input.credential ?? "switcher-local-no-auth";
11107
11121
  const picker = { modelPicker: { replaceBuiltInOptions: true, options: input.models.map((m) => ({ model: m.id, label: m.name, description: m.description?.slice(0, 300) })) } };
11108
- const file2 = input.sessionDir ? await durableJsonFile(join15(input.sessionDir, "settings"), "claude-settings", picker) : await jsonFile(input.stateDir, "claude-settings.json", picker);
11122
+ const file2 = input.sessionDir ? await durableJsonFile(claudeSettingsDirectory(input.sessionDir), "claude-settings", picker) : await jsonFile(input.stateDir, "claude-settings.json", picker);
11109
11123
  configPaths.push(file2);
11110
11124
  warnings.push("Claude managed settings and model allowlists can restrict the generated picker.");
11111
11125
  return { executable, args: ["--settings", file2, "--model", input.model, ...args], env, configPaths, warnings };
@@ -11519,8 +11533,8 @@ exec "$SWITCHER_ORI_NATIVE_EXECUTABLE" ${prepared.args.map(quote2).join(" ")}
11519
11533
  }
11520
11534
 
11521
11535
  // src/launcher.ts
11522
- import { mkdir as mkdir14, mkdtemp, realpath as realpath8, rm as rm6, writeFile as writeFile18 } from "fs/promises";
11523
- import { join as join24, resolve as resolve14 } from "path";
11536
+ import { lstat as lstat13, mkdir as mkdir14, mkdtemp, realpath as realpath8, rm as rm6, writeFile as writeFile18 } from "fs/promises";
11537
+ import { join as join24, relative as relative7, resolve as resolve14 } from "path";
11524
11538
 
11525
11539
  // src/provider-credential-onboarding.ts
11526
11540
  import { z as z9 } from "zod-v4";
@@ -13365,19 +13379,24 @@ async function assertNativeStateIsolation(tool, home, environment = process.env)
13365
13379
  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.");
13366
13380
  }
13367
13381
  }
13382
+ function nativeStateLockPath(state) {
13383
+ return join17(state.home, ".switcher-shared-state.lock");
13384
+ }
13385
+ function nativeStateLockFault(entry) {
13386
+ if (!entry?.isFile() || entry.isSymbolicLink() || entry.uid !== process.getuid?.() || (entry.mode & 63) !== 0)
13387
+ return new Fault(422, "native_state_lock", "The shared-state lock has unsafe ownership, permissions or type.");
13388
+ return new Fault(409, "native_state_busy", "Another Switcher projection/import owns this corpus, or a prior operation ended before releasing its lock. Inspect native processes and the lock before retrying.");
13389
+ }
13368
13390
  async function withNativeStateLock(state, operation) {
13369
13391
  await ensureNativeStateDirectory(state.home);
13370
- const path = join17(state.home, ".switcher-shared-state.lock");
13392
+ const path = nativeStateLockPath(state);
13371
13393
  let handle;
13372
13394
  try {
13373
13395
  handle = await open5(path, "wx", 384);
13374
13396
  } catch (error) {
13375
13397
  if (error.code !== "EEXIST")
13376
13398
  throw error;
13377
- const entry = await info(path);
13378
- if (!entry?.isFile() || entry.isSymbolicLink() || entry.uid !== process.getuid?.() || (entry.mode & 63) !== 0)
13379
- throw new Fault(422, "native_state_lock", "The shared-state lock has unsafe ownership, permissions or type.");
13380
- throw new Fault(409, "native_state_busy", "Another Switcher projection/import owns this corpus, or a prior operation ended before releasing its lock. Inspect native processes and the lock before retrying.");
13399
+ throw nativeStateLockFault(await info(path));
13381
13400
  }
13382
13401
  const identity = await handle.stat();
13383
13402
  try {
@@ -13547,10 +13566,13 @@ async function codexInstructionProjection(home, config, allowedExternalFiles = {
13547
13566
  }
13548
13567
  return instructions;
13549
13568
  }
13550
- async function assertNativeInstructionOverlay(state, overlayHome) {
13569
+ async function assertNativeInstructionOverlay(state, overlayHome, options = {}) {
13551
13570
  if (state.tool !== "codex" || absolute(overlayHome) === state.home)
13552
13571
  return;
13553
- await assertNativeStateDirectory(overlayHome);
13572
+ if (options.plan && !await info(absolute(overlayHome)))
13573
+ await assertCreatableNativeStateDirectory(absolute(overlayHome));
13574
+ else
13575
+ await assertNativeStateDirectory(overlayHome);
13554
13576
  const config = await readCodexStateConfig(overlayHome);
13555
13577
  if (config.profiles !== undefined || config.include !== undefined)
13556
13578
  throw new Fault(422, "native_state_instruction_overlay", "Private Codex profile/include instruction overlays are not supported. Resolve their effective canonical instructions before launching.");
@@ -13670,10 +13692,25 @@ async function createTrackedDirectory(path, created) {
13670
13692
  await assertNativeStateDirectory(path);
13671
13693
  }
13672
13694
  }
13673
- async function projectNativeStateUnlocked(state, overlayHome) {
13695
+ async function assertCreatableNativeStateDirectory(path) {
13696
+ let existing = dirname8(path);
13697
+ while (!await info(existing) && existing !== dirname8(existing))
13698
+ existing = dirname8(existing);
13699
+ if (await realpath6(existing) !== existing)
13700
+ assertNativeDirectoryEntry(await info(path), path, true);
13701
+ await assertSafeAncestors(existing);
13702
+ }
13703
+ async function preflightNativeStateProjection(state, overlayHome, plan = false) {
13674
13704
  overlayHome = absolute(overlayHome);
13675
- await assertNativeStateDirectory(state.home);
13676
- await assertNativeStateDirectory(overlayHome);
13705
+ const corpus = !plan || Boolean(await info(state.home)), overlay = !plan || Boolean(await info(overlayHome));
13706
+ if (corpus)
13707
+ await assertNativeStateDirectory(state.home);
13708
+ else
13709
+ await ensureNativeStateDirectory(state.home, false);
13710
+ if (overlay)
13711
+ await assertNativeStateDirectory(overlayHome);
13712
+ else
13713
+ await assertCreatableNativeStateDirectory(overlayHome);
13677
13714
  if (overlayHome === state.home)
13678
13715
  return;
13679
13716
  const contains = (parent, child) => {
@@ -13685,9 +13722,11 @@ async function projectNativeStateUnlocked(state, overlayHome) {
13685
13722
  await assertCodexDatabaseRedirectSafe(state, overlayHome);
13686
13723
  for (const entry of NATIVE_STATE_ENTRIES[state.tool]) {
13687
13724
  const target = join17(state.home, entry.name), destination = join17(overlayHome, entry.name);
13688
- await ensureNativeStateDirectory(dirname8(target), false);
13689
- await ensureNativeStateDirectory(dirname8(destination), false);
13690
- const source = await info(target), existing = await info(destination);
13725
+ if (corpus)
13726
+ await ensureNativeStateDirectory(dirname8(target), false);
13727
+ if (overlay)
13728
+ await ensureNativeStateDirectory(dirname8(destination), false);
13729
+ const source = corpus ? await info(target) : undefined, existing = overlay ? await info(destination) : undefined;
13691
13730
  if (source && (source.isSymbolicLink() || source.uid !== process.getuid?.() || writableByOthers(source) || source.isFile() && source.nlink !== 1 || (entry.kind === "directory" ? !source.isDirectory() : !source.isFile())))
13692
13731
  throw new Fault(422, "native_state_entry", `The shared native state entry ${displayPath(target)} must be a ${entry.kind === "directory" ? "real directory" : "regular file with a single link"} owned by you and not writable by other users. ${writeFix}.`);
13693
13732
  if (source?.isDirectory())
@@ -13695,6 +13734,12 @@ async function projectNativeStateUnlocked(state, overlayHome) {
13695
13734
  if (existing && (!existing.isSymbolicLink() || resolve10(dirname8(destination), await readlink(destination)) !== target))
13696
13735
  throw new Fault(409, "native_state_migration_required", `This launch profile already contains native state at ${displayPath(destination)}, which is not a link to ${displayPath(target)}. Preserve and migrate its noncredential state before linking the shared corpus.`);
13697
13736
  }
13737
+ }
13738
+ async function projectNativeStateUnlocked(state, overlayHome) {
13739
+ overlayHome = absolute(overlayHome);
13740
+ await preflightNativeStateProjection(state, overlayHome);
13741
+ if (overlayHome === state.home)
13742
+ return;
13698
13743
  const createdLinks = [];
13699
13744
  const createdFiles = [], createdDirectories = [];
13700
13745
  try {
@@ -13752,6 +13797,14 @@ async function projectNativeState(state, overlayHome) {
13752
13797
  return;
13753
13798
  return withNativeStateLock(state, () => projectNativeStateUnlocked(state, overlayHome));
13754
13799
  }
13800
+ async function checkNativeStateProjection(state, overlayHome) {
13801
+ if (absolute(overlayHome) === state.home)
13802
+ return;
13803
+ const lock = await info(nativeStateLockPath(state));
13804
+ if (lock)
13805
+ throw nativeStateLockFault(lock);
13806
+ return preflightNativeStateProjection(state, overlayHome, true);
13807
+ }
13755
13808
 
13756
13809
  // src/chatgpt-launch.ts
13757
13810
  var object5 = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
@@ -14184,7 +14237,7 @@ async function applyDesktopSelection(library, config, label2, checkpoint) {
14184
14237
  import { constants as constants9 } from "fs";
14185
14238
  import { lstat as lstat10, open as open6, writeFile as writeFile16 } from "fs/promises";
14186
14239
  import { homedir as homedir10 } from "os";
14187
- import { join as join20, resolve as resolve11 } from "path";
14240
+ import { join as join20, relative as relative6, resolve as resolve11 } from "path";
14188
14241
  var preferences = new Set([
14189
14242
  "$schema",
14190
14243
  "permissions",
@@ -14232,7 +14285,12 @@ function routingOrCredentialEnvironmentKey(key) {
14232
14285
  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);
14233
14286
  }
14234
14287
  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.`);
14235
- async function readSettings(home) {
14288
+ async function readSettings(home, created) {
14289
+ const inside3 = created !== undefined && ((suffix) => suffix !== ".." && !suffix.startsWith("../"))(relative6(created, home));
14290
+ if (inside3 && !await lstat10(home).catch(() => {
14291
+ return;
14292
+ }))
14293
+ return;
14236
14294
  await ensureNativeStateDirectory(home, false);
14237
14295
  const path = join20(home, "settings.json");
14238
14296
  const entry = await lstat10(path).catch((error) => {
@@ -14299,10 +14357,10 @@ function project(settings2, existing, path) {
14299
14357
  }
14300
14358
  return { settings: result, dropped };
14301
14359
  }
14302
- async function prepareClaudeUserSettings(overlayHome, environment = process.env, corpusHome) {
14360
+ async function prepareClaudeUserSettings(overlayHome, environment = process.env, corpusHome, options = {}) {
14303
14361
  overlayHome = resolve11(overlayHome);
14304
14362
  const target = join20(overlayHome, "settings.json");
14305
- const existing = await readSettings(overlayHome);
14363
+ const existing = await readSettings(overlayHome, options.write === false ? options.created : undefined);
14306
14364
  if (existing !== undefined) {
14307
14365
  project(existing, true, target);
14308
14366
  return [];
@@ -14314,6 +14372,9 @@ async function prepareClaudeUserSettings(overlayHome, environment = process.env,
14314
14372
  if (source === undefined)
14315
14373
  return [];
14316
14374
  const { settings: settings2, dropped } = project(source, false, join20(sourceHome, "settings.json"));
14375
+ const warnings = dropped.length ? [`Claude user settings not copied to this launch's private settings (unsupported keys): ${dropped.map((key) => JSON.stringify(key)).join(", ")}.`] : [];
14376
+ if (options.write === false)
14377
+ return warnings;
14317
14378
  await ensureNativeStateDirectory(overlayHome);
14318
14379
  try {
14319
14380
  await writeFile16(target, JSON.stringify(settings2, null, 2) + `
@@ -14325,7 +14386,7 @@ async function prepareClaudeUserSettings(overlayHome, environment = process.env,
14325
14386
  if (concurrent === undefined || JSON.stringify(project(concurrent, true, target).settings) !== JSON.stringify(settings2))
14326
14387
  throw new Fault(409, "claude_user_settings_changed", `The private Claude settings ${displayPath(target)} changed during preparation. Existing settings were preserved; retry after resolving the concurrent launch.`);
14327
14388
  }
14328
- return dropped.length ? [`Claude user settings not copied to this launch's private settings (unsupported keys): ${dropped.map((key) => JSON.stringify(key)).join(", ")}.`] : [];
14389
+ return warnings;
14329
14390
  }
14330
14391
 
14331
14392
  // src/claude-desktop-launch.ts
@@ -16143,6 +16204,57 @@ async function prepareOriForPlan(plan, options) {
16143
16204
  throw error;
16144
16205
  }
16145
16206
  }
16207
+ async function sharedNativeHome(state, root, profileId, environment = process.env) {
16208
+ const variable = state.tool === "codex" ? "CODEX_HOME" : "CLAUDE_CONFIG_DIR";
16209
+ const configured = environment[variable] ? resolve14(environment[variable]) : undefined;
16210
+ const configuredCorpus = configured !== undefined && await realpath8(configured).catch(() => configured) === state.home;
16211
+ const home = state.tool === "claude" && (!configured || configured === state.home || configuredCorpus) ? join24(root, "native-claude", profileId) : configured ?? state.home;
16212
+ return { home, settingsEnvironment: configuredCorpus ? { ...environment, CLAUDE_CONFIG_DIR: undefined } : environment };
16213
+ }
16214
+ var SESSION_DIRECTORY_HARNESSES = ["pi", "omp", "dsh", "cline", "hermes", "prime-agent", "gemini", "aider", "opencode", "kilo", "antigravity", "junie", "claude"];
16215
+ function launchSessionDirectory(root, harness, profileId) {
16216
+ return join24(root, "sessions", harness, profileId);
16217
+ }
16218
+ async function checkSharedNativeLaunch(state, root, profileId, options = {}) {
16219
+ const warnings = await legacyNativeStateWarnings(root, state);
16220
+ if (options.desktop)
16221
+ return warnings;
16222
+ const overlay = await sharedNativeHome(state, root, profileId);
16223
+ const suffix = relative7(root, overlay.home);
16224
+ const created = suffix !== ".." && !suffix.startsWith("../") && !await lstat13(root).catch(() => {
16225
+ return;
16226
+ }) ? root : undefined;
16227
+ if (created)
16228
+ await assertCreatableNativeStateDirectory(created);
16229
+ if (state.tool === "claude")
16230
+ warnings.push(...await prepareClaudeUserSettings(overlay.home, overlay.settingsEnvironment, state.home, { write: false, created }));
16231
+ await checkPrivateDirectory(overlay.home);
16232
+ await assertNativeInstructionOverlay(state, overlay.home, { plan: true });
16233
+ await checkNativeStateProjection(state, overlay.home);
16234
+ return warnings;
16235
+ }
16236
+ function isolatedNativeHome(tool, root, profileId, options = {}, environment = process.env) {
16237
+ if (options.desktop)
16238
+ return { home: join24(root, "desktop", profileId, "codex"), private: false };
16239
+ if (options.claudeDesktop)
16240
+ return { home: join24(root, "desktop-claude", profileId), private: false };
16241
+ const configured = environment[tool === "codex" ? "CODEX_HOME" : "CLAUDE_CONFIG_DIR"];
16242
+ return { home: configured ? resolve14(configured) : join24(root, `native-${tool}`, profileId), private: true };
16243
+ }
16244
+ async function checkDirectLaunch(root, profileId, harness, options = {}) {
16245
+ const desktop = Boolean(options.desktop || options.claudeDesktop);
16246
+ await checkPrivateDirectory(root);
16247
+ const warnings = options.sharedState ? await checkSharedNativeLaunch(options.sharedState, root, profileId, { desktop }) : [];
16248
+ if (options.isolated && (harness === "codex" || harness === "claude")) {
16249
+ const isolated = isolatedNativeHome(harness, root, profileId, options);
16250
+ await assertNativeStateIsolation(harness, isolated.home);
16251
+ if (isolated.private)
16252
+ await checkPrivateDirectory(isolated.home);
16253
+ }
16254
+ if (harness === "claude" && !desktop)
16255
+ await checkPrivateDirectory(claudeSettingsDirectory(launchSessionDirectory(root, harness, profileId)));
16256
+ return warnings;
16257
+ }
16146
16258
  async function launch(client, profileId, options = {}) {
16147
16259
  if (options.backend === "ori" && options.shareNativeState === false)
16148
16260
  throw new Fault(400, "native_state_backend", "Explicit native-state isolation requires the direct adapter; Ori isolation is not yet verified.");
@@ -16253,28 +16365,22 @@ async function launch(client, profileId, options = {}) {
16253
16365
  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)] : [];
16254
16366
  let nativeHome2;
16255
16367
  if (sharedState && !options.desktop && !options.claudeDesktop) {
16256
- const variable = sharedState.tool === "codex" ? "CODEX_HOME" : "CLAUDE_CONFIG_DIR";
16257
- const configured = process.env[variable] ? resolve14(process.env[variable]) : undefined;
16258
- const configuredCorpus = configured && await realpath8(configured).catch(() => configured) === sharedState.home;
16259
- nativeHome2 = sharedState.tool === "claude" && (!configured || configured === sharedState.home || configuredCorpus) ? join24(root, "native-claude", profileId) : configured ?? sharedState.home;
16368
+ const overlay = await sharedNativeHome(sharedState, root, profileId);
16369
+ nativeHome2 = overlay.home;
16260
16370
  if (sharedState.tool === "claude")
16261
- stateWarnings.push(...await prepareClaudeUserSettings(nativeHome2, configuredCorpus ? { ...process.env, CLAUDE_CONFIG_DIR: undefined } : process.env, sharedState.home));
16371
+ stateWarnings.push(...await prepareClaudeUserSettings(nativeHome2, overlay.settingsEnvironment, sharedState.home));
16262
16372
  await privateDirectory(nativeHome2);
16263
16373
  await assertNativeInstructionOverlay(sharedState, nativeHome2);
16264
16374
  await projectNativeState(sharedState, nativeHome2);
16265
16375
  }
16266
16376
  if (options.shareNativeState === false && backend === "direct") {
16267
16377
  const tool = plan.profile.harness;
16268
- if (options.desktop)
16269
- await assertNativeStateIsolation(tool, join24(root, "desktop", desktopState, "codex"));
16270
- else if (options.claudeDesktop)
16271
- await assertNativeStateIsolation(tool, join24(root, "desktop-claude", desktopState));
16272
- else {
16273
- const variable = tool === "codex" ? "CODEX_HOME" : "CLAUDE_CONFIG_DIR";
16274
- nativeHome2 = process.env[variable] ? resolve14(process.env[variable]) : join24(root, `native-${tool}`, profileId);
16275
- await assertNativeStateIsolation(tool, nativeHome2);
16276
- await privateDirectory(nativeHome2);
16277
- }
16378
+ const isolated = isolatedNativeHome(tool, root, desktopState, { desktop: Boolean(options.desktop), claudeDesktop: Boolean(options.claudeDesktop) });
16379
+ if (isolated.private)
16380
+ nativeHome2 = isolated.home;
16381
+ await assertNativeStateIsolation(tool, isolated.home);
16382
+ if (isolated.private)
16383
+ await privateDirectory(isolated.home);
16278
16384
  }
16279
16385
  const input = {
16280
16386
  harness: plan.profile.harness,
@@ -16311,7 +16417,7 @@ async function launch(client, profileId, options = {}) {
16311
16417
  version: detection?.version,
16312
16418
  sharedState,
16313
16419
  gatewayHost,
16314
- ...["pi", "omp", "dsh", "cline", "hermes", "prime-agent", "gemini", "aider", "opencode", "kilo", "antigravity", "junie", "claude"].includes(plan.profile.harness) ? { sessionDir: join24(root, "sessions", plan.profile.harness, profileId) } : {}
16420
+ ...SESSION_DIRECTORY_HARNESSES.includes(plan.profile.harness) ? { sessionDir: launchSessionDirectory(root, plan.profile.harness, profileId) } : {}
16315
16421
  });
16316
16422
  cleanup = prepared.cleanup;
16317
16423
  prepared = { ...prepared, warnings: [...prepared.warnings, ...stateWarnings] };
@@ -16550,14 +16656,14 @@ async function ensureLaunchProfile(client, provider, harness, model3, modelPolic
16550
16656
  // src/native-state-import.ts
16551
16657
  import { createHash as createHash18 } from "crypto";
16552
16658
  import { constants as constants11 } from "fs";
16553
- import { lstat as lstat13, open as open9, opendir as opendir2, link as link3, rmdir as rmdir2, unlink as unlink5 } from "fs/promises";
16554
- import { basename as basename6, dirname as dirname11, isAbsolute as isAbsolute19, join as join25, relative as relative6, resolve as resolve15 } from "path";
16659
+ import { lstat as lstat14, open as open9, opendir as opendir2, link as link3, rmdir as rmdir2, unlink as unlink5 } from "fs/promises";
16660
+ import { basename as basename6, dirname as dirname11, isAbsolute as isAbsolute19, join as join25, relative as relative8, resolve as resolve15 } from "path";
16555
16661
  var MAX_FILES = 1e5;
16556
16662
  var MAX_BYTES2 = 2 * 1024 * 1024 * 1024;
16557
16663
  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.");
16558
16664
  async function info2(path) {
16559
16665
  try {
16560
- return await lstat13(path);
16666
+ return await lstat14(path);
16561
16667
  } catch (error) {
16562
16668
  if (error.code === "ENOENT")
16563
16669
  return;
@@ -16567,7 +16673,7 @@ async function info2(path) {
16567
16673
  var identity = (s) => ({ dev: s.dev, ino: s.ino, size: s.size, mtimeMs: s.mtimeMs, ctimeMs: s.ctimeMs });
16568
16674
  var same = (a, b) => JSON.stringify(identity(a)) === JSON.stringify(identity(b));
16569
16675
  var inside3 = (parent, child) => {
16570
- const path = relative6(parent, child);
16676
+ const path = relative8(parent, child);
16571
16677
  return path !== ".." && !path.startsWith("../") && !isAbsolute19(path);
16572
16678
  };
16573
16679
  var SESSION_ID = /^[a-f\d]{8}(?:-[a-f\d]{4}){3}-[a-f\d]{12}$/i;
@@ -16587,7 +16693,7 @@ async function sessionId(path, expected) {
16587
16693
  length += read.bytesRead;
16588
16694
  newline = buffer.indexOf(10, 0);
16589
16695
  }
16590
- const after = await handle.stat(), named = await lstat13(path);
16696
+ const after = await handle.stat(), named = await lstat14(path);
16591
16697
  if (!same(before, after) || !same(after, named) || after.nlink !== 1 || named.nlink !== 1 || named.isSymbolicLink())
16592
16698
  throw refused();
16593
16699
  if (newline < 0 && before.size > buffer.length)
@@ -16686,7 +16792,7 @@ async function fingerprint2(path, copyTo) {
16686
16792
  offset += (await output.write(chunk, offset, chunk.length - offset)).bytesWritten;
16687
16793
  }
16688
16794
  }
16689
- const after = await handle.stat(), named = await lstat13(path);
16795
+ const after = await handle.stat(), named = await lstat14(path);
16690
16796
  if (named.isSymbolicLink() || after.nlink !== 1 || named.nlink !== 1 || bytes !== before.size || !same(before, after) || !same(after, named))
16691
16797
  throw refused();
16692
16798
  await output?.sync();
@@ -17336,16 +17442,23 @@ async function main(args = process.argv.slice(2)) {
17336
17442
  const sharedNativeState = ["codex", "claude"].includes(plan.profile.harness) && nativeStateRequested(plan.profile.harness, process.env, shareNativeState);
17337
17443
  const suffix = plan.profile.harness.toUpperCase();
17338
17444
  const marked = process.env[`HASNA_${suffix}_STATE_HOME`] !== undefined || process.env[`SUBSCRIPTIONS_SHARED_HOME_${suffix}`] !== undefined;
17339
- const nativeState = sharedNativeState ? { shared: true, consent: shareNativeState === true ? "command" : marked ? "environment" : "default" } : shareNativeState === false ? { shared: false, consent: "command" } : undefined;
17340
17445
  if ((sharedNativeState || shareNativeState === false) && plan.profile.harness === "codex")
17341
17446
  assertHarnessArguments("codex", nativeArgs, { reservedCodexRoots: ["sqlite_home"] });
17342
- if (sharedNativeState)
17447
+ const root = resolve16(values2["state-dir"] ?? join26(switcherHome(), "state"));
17448
+ if (backend !== "direct")
17449
+ await checkPrivateDirectory(root);
17450
+ const nativeWarnings = backend === "direct" ? await checkDirectLaunch(root, profileId, plan.profile.harness, {
17451
+ desktop: Boolean(desktop),
17452
+ claudeDesktop: Boolean(claudeApp),
17453
+ isolated: shareNativeState === false,
17454
+ ...sharedNativeState ? { sharedState: await resolveNativeState(plan.profile.harness, process.env, { create: false }) } : {}
17455
+ }) : [];
17456
+ const nativeState = sharedNativeState ? { shared: true, consent: shareNativeState === true ? "command" : marked ? "environment" : "default", ...nativeWarnings.length ? { warnings: nativeWarnings } : {} } : shareNativeState === false ? { shared: false, consent: "command" } : undefined;
17457
+ if (sharedNativeState && backend !== "direct")
17343
17458
  await resolveNativeState(plan.profile.harness, process.env, { create: false });
17344
- if (shareNativeState === false) {
17345
- const tool = plan.profile.harness, root = resolve16(values2["state-dir"] ?? join26(switcherHome(), "state"));
17346
- const configured = process.env[tool === "codex" ? "CODEX_HOME" : "CLAUDE_CONFIG_DIR"];
17347
- const home = desktop ? join26(root, "desktop", profileId, "codex") : claudeApp ? join26(root, "desktop-claude", profileId) : configured ? resolve16(configured) : join26(root, `native-${tool}`, profileId);
17348
- await assertNativeStateIsolation(tool, home);
17459
+ if (shareNativeState === false && backend !== "direct") {
17460
+ const tool = plan.profile.harness;
17461
+ await assertNativeStateIsolation(tool, isolatedNativeHome(tool, root, profileId, { desktop: Boolean(desktop), claudeDesktop: Boolean(claudeApp) }).home);
17349
17462
  }
17350
17463
  if (backend === "ori") {
17351
17464
  if (sharedNativeState)
@@ -16,6 +16,14 @@ export declare function detectHarness(harness: HarnessId, override?: string): Pr
16
16
  }>;
17
17
  export declare function validateHarnessConfiguration(harness: HarnessId, cwd: string, args?: readonly string[]): Promise<void>;
18
18
  export declare function validateHarnessVersion(harness: HarnessId, version: string | undefined): void;
19
+ /**
20
+ * A JSON file named by its content and kept outside the launch's state directory. Claude
21
+ * Code's background host replays a session's launch flags when it restarts the session,
22
+ * possibly long after the launch ended, so a file named in those flags must outlive it.
23
+ * An existing file is reused only when it is this user's private regular file with exactly this content.
24
+ */
25
+ /** The folder a Claude launch keeps its --settings file in, inside its session folder. */
26
+ export declare function claudeSettingsDirectory(sessionDir: string): string;
19
27
  export declare function codexModel(model: HarnessLaunchInput["models"][number], priority: number, baseUrl?: string, selectedReasoning?: ReasoningEffort): {
20
28
  slug: string;
21
29
  display_name: string;