@minniexcode/codex-switch 0.0.10 → 0.0.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.
Files changed (38) hide show
  1. package/README.AI.md +52 -15
  2. package/README.CN.md +81 -48
  3. package/README.md +75 -34
  4. package/dist/app/add-provider.js +29 -15
  5. package/dist/app/bridge.js +15 -14
  6. package/dist/app/edit-provider.js +1 -1
  7. package/dist/app/get-status.js +13 -6
  8. package/dist/app/import-providers.js +1 -1
  9. package/dist/app/init-codex.js +13 -14
  10. package/dist/app/remove-provider.js +1 -1
  11. package/dist/app/run-doctor.js +12 -5
  12. package/dist/app/run-mutation.js +3 -2
  13. package/dist/app/setup-codex.js +3 -1
  14. package/dist/app/switch-provider.js +11 -13
  15. package/dist/cli.js +34 -2
  16. package/dist/commands/args.js +2 -2
  17. package/dist/commands/dispatch.js +40 -0
  18. package/dist/commands/handlers.js +121 -156
  19. package/dist/commands/help.js +2 -0
  20. package/dist/commands/registry.js +28 -9
  21. package/dist/domain/backups.js +4 -4
  22. package/dist/domain/config.js +110 -5
  23. package/dist/domain/providers.js +12 -0
  24. package/dist/domain/runtime-state.js +81 -5
  25. package/dist/runtime/copilot-adapter.js +12 -12
  26. package/dist/runtime/copilot-bridge.js +392 -44
  27. package/dist/runtime/copilot-cli.js +84 -12
  28. package/dist/runtime/copilot-installer.js +10 -9
  29. package/dist/runtime/copilot-sdk-loader.js +5 -5
  30. package/dist/storage/backup-repo.js +4 -4
  31. package/dist/storage/codex-paths.js +34 -8
  32. package/dist/storage/lock-repo.js +2 -4
  33. package/dist/storage/runtime-state-repo.js +14 -13
  34. package/dist/storage/tool-config-repo.js +111 -0
  35. package/docs/Design/codex-switch-v0.0.11-design.md +824 -0
  36. package/docs/PRD/codex-switch-prd-v0.0.11.md +577 -0
  37. package/docs/cli-usage.md +166 -295
  38. package/package.json +1 -1
@@ -22,13 +22,14 @@ async function startBridge(args) {
22
22
  requestedProviderName: args.providerName ?? null,
23
23
  providers,
24
24
  configPath: args.configPath,
25
+ runtimeDir: args.runtimeDir,
25
26
  runtime: args.runtime,
26
27
  json: args.json,
27
28
  commandName: "start",
28
29
  preferRuntimeState: false,
29
30
  });
30
- await requireBridgeRuntimeReadiness();
31
- const bridge = await (0, copilot_bridge_1.ensureCopilotBridge)(target.providerName, target.provider);
31
+ await requireBridgeRuntimeReadiness(args.runtimesDir);
32
+ const bridge = await (0, copilot_bridge_1.ensureCopilotBridge)(target.providerName, target.provider, args.runtimeDir);
32
33
  const nextProvider = bridge.portChanged ? rewriteBridgeProviderPort(target.provider, bridge.port) : target.provider;
33
34
  if (bridge.portChanged) {
34
35
  try {
@@ -43,7 +44,7 @@ async function startBridge(args) {
43
44
  }
44
45
  catch (error) {
45
46
  if (!bridge.reused) {
46
- (0, copilot_bridge_1.stopCopilotBridge)();
47
+ (0, copilot_bridge_1.stopCopilotBridge)(args.runtimeDir);
47
48
  }
48
49
  throw error;
49
50
  }
@@ -66,7 +67,7 @@ async function startBridge(args) {
66
67
  */
67
68
  async function stopBridge(args) {
68
69
  const providers = (0, providers_repo_1.readProvidersFile)(args.providersPath);
69
- const state = (0, runtime_state_repo_1.readCopilotBridgeState)();
70
+ const state = (0, runtime_state_repo_1.readCopilotBridgeState)(args.runtimeDir);
70
71
  if (!state && !args.providerName) {
71
72
  return {
72
73
  data: {
@@ -90,6 +91,7 @@ async function stopBridge(args) {
90
91
  requestedProviderName: args.providerName ?? null,
91
92
  providers,
92
93
  configPath: args.configPath,
94
+ runtimeDir: args.runtimeDir,
93
95
  runtime: args.runtime,
94
96
  json: args.json,
95
97
  commandName: "stop",
@@ -101,7 +103,7 @@ async function stopBridge(args) {
101
103
  requestedProvider: args.providerName,
102
104
  });
103
105
  }
104
- (0, copilot_bridge_1.stopCopilotBridge)();
106
+ (0, copilot_bridge_1.stopCopilotBridge)(args.runtimeDir);
105
107
  return {
106
108
  data: {
107
109
  provider: target.providerName,
@@ -115,18 +117,19 @@ async function stopBridge(args) {
115
117
  */
116
118
  async function statusBridge(args) {
117
119
  const providers = (0, providers_repo_1.readProvidersFile)(args.providersPath);
118
- const state = (0, runtime_state_repo_1.readCopilotBridgeState)();
120
+ const state = (0, runtime_state_repo_1.readCopilotBridgeState)(args.runtimeDir);
119
121
  const target = await resolveBridgeTarget({
120
122
  requestedProviderName: args.providerName ?? null,
121
123
  providers,
122
124
  configPath: args.configPath,
125
+ runtimeDir: args.runtimeDir,
123
126
  runtime: args.runtime,
124
127
  json: args.json,
125
128
  commandName: "status",
126
129
  preferRuntimeState: true,
127
130
  });
128
131
  const provider = target.provider;
129
- const runtimeStatus = await (0, copilot_bridge_1.probeCopilotBridgeRuntime)(provider);
132
+ const runtimeStatus = await (0, copilot_bridge_1.probeCopilotBridgeRuntime)(provider, state, args.runtimeDir);
130
133
  const expectedBaseUrl = (0, providers_1.buildCopilotBridgeBaseUrl)(provider.runtime);
131
134
  if (args.providerName && state?.provider && state.provider !== args.providerName) {
132
135
  throw (0, errors_1.cliError)("BRIDGE_PROVIDER_MISMATCH", `Bridge runtime state belongs to "${state.provider}" not "${args.providerName}".`, {
@@ -154,7 +157,7 @@ async function resolveBridgeTarget(args) {
154
157
  return resolveNamedBridgeProvider(args.providers, args.requestedProviderName);
155
158
  }
156
159
  if (args.preferRuntimeState) {
157
- const runtimeState = (0, runtime_state_repo_1.readCopilotBridgeState)();
160
+ const runtimeState = (0, runtime_state_repo_1.readCopilotBridgeState)(args.runtimeDir);
158
161
  if (runtimeState?.provider && args.providers.providers[runtimeState.provider]) {
159
162
  return resolveNamedBridgeProvider(args.providers, runtimeState.provider);
160
163
  }
@@ -238,15 +241,15 @@ async function promptForCopilotBridgeSelection(runtime, targets, commandName) {
238
241
  /**
239
242
  * Verifies that the local Copilot bridge prerequisites are available before startup.
240
243
  */
241
- async function requireBridgeRuntimeReadiness() {
242
- const installStatus = (0, copilot_installer_1.probeCopilotSdkInstall)();
244
+ async function requireBridgeRuntimeReadiness(runtimesDir) {
245
+ const installStatus = (0, copilot_installer_1.probeCopilotSdkInstall)(runtimesDir);
243
246
  if (!installStatus.installed) {
244
247
  throw (0, errors_1.cliError)("COPILOT_SDK_MISSING", "The optional Copilot SDK runtime is not installed.", {
245
248
  installDir: installStatus.installDir,
246
249
  packageName: installStatus.packageName,
247
250
  });
248
251
  }
249
- await (0, copilot_adapter_1.readCopilotAuthState)();
252
+ await (0, copilot_adapter_1.readCopilotAuthState)(runtimesDir);
250
253
  }
251
254
  /**
252
255
  * Rewrites one Copilot bridge provider record with a recovered runtime port.
@@ -281,9 +284,7 @@ function persistRecoveredBridgePort(args) {
281
284
  const document = (0, config_repo_1.readStructuredConfig)(args.configPath);
282
285
  const configPlan = (0, config_repo_1.createConfigMutationPlan)(document, {
283
286
  upsertModelProviders: {
284
- [args.provider.profile]: {
285
- baseUrl: (0, providers_1.buildCopilotBridgeBaseUrl)(args.provider.runtime),
286
- },
287
+ [args.provider.profile]: (0, providers_1.buildCopilotModelProviderProjection)(args.provider.runtime),
287
288
  },
288
289
  });
289
290
  (0, config_repo_1.applyConfigMutation)(args.configPath, document, configPlan);
@@ -109,7 +109,7 @@ function editProvider(args) {
109
109
  switchToProfile: args.switchToProfile ?? null,
110
110
  });
111
111
  return (0, run_mutation_1.runMutation)({
112
- codexDir: args.codexDir,
112
+ lockPath: args.lockPath,
113
113
  backupsDir: args.backupsDir,
114
114
  latestBackupPath: args.latestBackupPath,
115
115
  operation: "edit",
@@ -48,7 +48,7 @@ const runtime_state_repo_1 = require("../storage/runtime-state-repo");
48
48
  /**
49
49
  * Reports the current on-disk runtime state and how it maps back to managed providers.
50
50
  */
51
- async function getStatus(codexDir, configPath, providersPath, authPath) {
51
+ async function getStatus(codexDir, configPath, providersPath, authPath, options) {
52
52
  const configExists = fs.existsSync(configPath);
53
53
  const providersExists = fs.existsSync(providersPath);
54
54
  let currentProfile = null;
@@ -69,8 +69,8 @@ async function getStatus(codexDir, configPath, providersPath, authPath) {
69
69
  const liveState = (0, runtime_state_1.inspectLiveStateDrift)(currentProfile, providers);
70
70
  const activeProviderCandidates = currentProfile && providers ? (0, providers_1.findProvidersByProfile)(providers, currentProfile) : [];
71
71
  const activeProvider = activeProviderCandidates.length === 1 && providers ? providers.providers[activeProviderCandidates[0]] : null;
72
- const copilotInstall = (0, copilot_installer_1.probeCopilotSdkInstall)();
73
- const runtimeStateInspection = (0, runtime_state_repo_1.inspectCopilotBridgeState)();
72
+ const copilotInstall = (0, copilot_installer_1.probeCopilotSdkInstall)(options?.runtimesDir);
73
+ const runtimeStateInspection = (0, runtime_state_repo_1.inspectCopilotBridgeState)(options?.runtimeDir);
74
74
  const runtimeState = runtimeStateInspection.state;
75
75
  const runtimeStateProvider = runtimeState && providers ? providers.providers[runtimeState.provider] ?? null : null;
76
76
  const bridgeProbeTarget = activeProvider && (0, providers_1.isCopilotBridgeProvider)(activeProvider)
@@ -86,7 +86,7 @@ async function getStatus(codexDir, configPath, providersPath, authPath) {
86
86
  cause: runtimeStateInspection.parseError ?? "Failed to parse Copilot bridge runtime state.",
87
87
  }
88
88
  : bridgeProbeTarget
89
- ? await (0, copilot_bridge_1.probeCopilotBridgeRuntime)(bridgeProbeTarget, runtimeState)
89
+ ? await (0, copilot_bridge_1.probeCopilotBridgeRuntime)(bridgeProbeTarget, runtimeState, options?.runtimeDir)
90
90
  : runtimeState
91
91
  ? {
92
92
  ok: false,
@@ -97,7 +97,7 @@ async function getStatus(codexDir, configPath, providersPath, authPath) {
97
97
  }
98
98
  : null;
99
99
  const copilotAuth = activeProvider && (0, providers_1.isCopilotBridgeProvider)(activeProvider)
100
- ? await (0, copilot_adapter_1.readCopilotAuthState)().catch((error) => ({
100
+ ? await (0, copilot_adapter_1.readCopilotAuthState)(options?.runtimesDir).catch((error) => ({
101
101
  ready: false,
102
102
  source: "official-sdk",
103
103
  mode: "session",
@@ -115,7 +115,14 @@ async function getStatus(codexDir, configPath, providersPath, authPath) {
115
115
  warnings,
116
116
  data: {
117
117
  codexDir,
118
- storage: (0, runtime_state_1.getStorageRoles)(),
118
+ storage: (0, runtime_state_1.getStorageRoles)({
119
+ codexDir,
120
+ providersPath,
121
+ configPath,
122
+ authPath,
123
+ runtimeDir: options?.runtimeDir,
124
+ runtimesDir: options?.runtimesDir,
125
+ }),
119
126
  configExists,
120
127
  providersExists,
121
128
  currentProfile,
@@ -62,7 +62,7 @@ function importProviders(args) {
62
62
  (0, fs_utils_1.ensureDir)(args.codexDir);
63
63
  const document = (0, config_repo_1.readStructuredConfig)(args.configPath);
64
64
  return (0, run_mutation_1.runMutation)({
65
- codexDir: args.codexDir,
65
+ lockPath: args.lockPath,
66
66
  backupsDir: args.backupsDir,
67
67
  latestBackupPath: args.latestBackupPath,
68
68
  operation: "import",
@@ -35,34 +35,33 @@ var __importStar = (this && this.__importStar) || (function () {
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.initCodex = initCodex;
37
37
  const fs = __importStar(require("node:fs"));
38
- const errors_1 = require("../domain/errors");
39
38
  const fs_utils_1 = require("../storage/fs-utils");
40
39
  const providers_repo_1 = require("../storage/providers-repo");
40
+ const tool_config_repo_1 = require("../storage/tool-config-repo");
41
41
  /**
42
- * Initializes a Codex directory for managed providers.json usage without requiring live Codex state.
42
+ * Initializes the codex-switch tool home without requiring target Codex runtime files.
43
43
  */
44
44
  function initCodex(args) {
45
- const codexDirExists = fs.existsSync(args.codexDir);
46
- if (!codexDirExists && !args.createCodexDir) {
47
- throw (0, errors_1.cliError)("CODEX_DIR_NOT_FOUND", "The requested Codex directory does not exist.", {
48
- codexDir: args.codexDir,
49
- });
50
- }
51
- if (!codexDirExists) {
52
- (0, fs_utils_1.ensureDir)(args.codexDir);
45
+ const toolHomeExists = fs.existsSync(args.toolHomeDir);
46
+ if (!toolHomeExists) {
47
+ (0, fs_utils_1.ensureDir)(args.toolHomeDir);
53
48
  }
49
+ const toolConfigExists = fs.existsSync(args.toolConfigPath);
50
+ const ensuredConfig = (0, tool_config_repo_1.ensureToolConfig)(args.toolConfigPath, args.version, args.defaultCodexDir ?? "");
54
51
  const providersExists = fs.existsSync(args.providersPath);
55
52
  if (!providersExists) {
56
53
  (0, providers_repo_1.writeProvidersFile)(args.providersPath, { providers: {} });
57
54
  }
58
55
  return {
59
56
  data: {
60
- codexDir: args.codexDir,
61
- createdCodexDir: !codexDirExists,
57
+ toolHomeDir: args.toolHomeDir,
58
+ toolConfigPath: args.toolConfigPath,
59
+ providersPath: args.providersPath,
60
+ createdToolHomeDir: !toolHomeExists,
61
+ createdToolConfigFile: ensuredConfig.created && !toolConfigExists,
62
62
  createdProvidersFile: !providersExists,
63
+ toolConfigAlreadyExisted: toolConfigExists,
63
64
  providersAlreadyExisted: providersExists,
64
- configExists: fs.existsSync(args.configPath),
65
- authExists: fs.existsSync(args.authPath),
66
65
  },
67
66
  };
68
67
  }
@@ -34,7 +34,7 @@ function removeProvider(args) {
34
34
  switchToProfile: args.switchToProfile ?? null,
35
35
  });
36
36
  return (0, run_mutation_1.runMutation)({
37
- codexDir: args.codexDir,
37
+ lockPath: args.lockPath,
38
38
  backupsDir: args.backupsDir,
39
39
  latestBackupPath: args.latestBackupPath,
40
40
  operation: "remove",
@@ -103,7 +103,7 @@ async function runDoctor(args) {
103
103
  }
104
104
  }
105
105
  const authState = (0, auth_repo_1.readAuthFileState)(args.authPath);
106
- const runtimeStateInspection = (0, runtime_state_repo_1.inspectCopilotBridgeState)();
106
+ const runtimeStateInspection = (0, runtime_state_repo_1.inspectCopilotBridgeState)(args.runtimeDir);
107
107
  const runtimeState = runtimeStateInspection.state;
108
108
  if (authState.exists && !authState.valid) {
109
109
  issues.push({
@@ -123,7 +123,7 @@ async function runDoctor(args) {
123
123
  if (matches.length === 1) {
124
124
  const activeProvider = providers.providers[matches[0]];
125
125
  if ((0, providers_1.isCopilotBridgeProvider)(activeProvider)) {
126
- const installStatus = (0, copilot_installer_1.probeCopilotSdkInstall)();
126
+ const installStatus = (0, copilot_installer_1.probeCopilotSdkInstall)(args.runtimesDir);
127
127
  if (!installStatus.installed) {
128
128
  issues.push({
129
129
  code: "COPILOT_SDK_MISSING",
@@ -133,7 +133,7 @@ async function runDoctor(args) {
133
133
  });
134
134
  }
135
135
  try {
136
- await (0, copilot_adapter_1.readCopilotAuthState)();
136
+ await (0, copilot_adapter_1.readCopilotAuthState)(args.runtimesDir);
137
137
  }
138
138
  catch (error) {
139
139
  const normalized = (0, errors_1.normalizeError)(error);
@@ -143,7 +143,7 @@ async function runDoctor(args) {
143
143
  ...(normalized.details ?? {}),
144
144
  });
145
145
  }
146
- const bridge = await (0, copilot_bridge_1.probeCopilotBridgeRuntime)(activeProvider, runtimeState);
146
+ const bridge = await (0, copilot_bridge_1.probeCopilotBridgeRuntime)(activeProvider, runtimeState, args.runtimeDir);
147
147
  if (!bridge.ok) {
148
148
  issues.push({
149
149
  code: mapBridgeDiagnosticCode(bridge.cause),
@@ -198,7 +198,14 @@ async function runDoctor(args) {
198
198
  healthy: issues.length === 0,
199
199
  issues,
200
200
  codexDir: args.codexDir,
201
- storage: (0, runtime_state_1.getStorageRoles)(),
201
+ storage: (0, runtime_state_1.getStorageRoles)({
202
+ codexDir: args.codexDir,
203
+ providersPath: args.providersPath,
204
+ configPath: args.configPath,
205
+ authPath: args.authPath,
206
+ runtimeDir: args.runtimeDir,
207
+ runtimesDir: args.runtimesDir,
208
+ }),
202
209
  liveState: drift,
203
210
  auth: authState,
204
211
  },
@@ -8,8 +8,9 @@ const lock_repo_1 = require("../storage/lock-repo");
8
8
  * Runs a write operation under a lock with automatic backup and rollback handling.
9
9
  */
10
10
  function runMutation(args) {
11
- return (0, lock_repo_1.withCodexLock)(args.codexDir, args.operation, () => {
12
- const backup = (0, backup_repo_1.createBackup)(args.codexDir, args.backupsDir, args.operation, args.files);
11
+ const lockPath = args.lockPath ?? require("node:path").join(args.codexDir ?? process.cwd(), ".codex-switch.lock");
12
+ return (0, lock_repo_1.withCodexLock)(lockPath, args.operation, () => {
13
+ const backup = (0, backup_repo_1.createBackup)(args.backupsDir, args.operation, args.files);
13
14
  try {
14
15
  const data = args.mutate({ backup });
15
16
  // Record the successful backup only after the mutation completes.
@@ -130,7 +130,7 @@ async function migrateCodex(args) {
130
130
  };
131
131
  const finalProviders = args.strategy === "merge" ? (0, providers_repo_1.mergeProviders)(currentProviders, nextProviders) : nextProviders;
132
132
  const result = (0, run_mutation_1.runMutation)({
133
- codexDir: args.codexDir,
133
+ lockPath: args.lockPath,
134
134
  backupsDir: args.backupsDir,
135
135
  latestBackupPath: args.latestBackupPath,
136
136
  operation: "migrate",
@@ -163,6 +163,8 @@ async function migrateCodex(args) {
163
163
  configPath: args.configPath,
164
164
  providersPath: args.providersPath,
165
165
  authPath: args.authPath,
166
+ runtimeDir: args.runtimeDir,
167
+ runtimesDir: args.runtimesDir,
166
168
  });
167
169
  return {
168
170
  data: {
@@ -23,15 +23,15 @@ async function switchProvider(args) {
23
23
  }
24
24
  const document = (0, config_repo_1.ensureProfileExists)(args.configPath, provider.profile, args.providerName);
25
25
  if ((0, providers_1.isCopilotBridgeProvider)(provider)) {
26
- const installStatus = (0, copilot_installer_1.probeCopilotSdkInstall)();
26
+ const installStatus = (0, copilot_installer_1.probeCopilotSdkInstall)(args.runtimesDir);
27
27
  if (!installStatus.installed) {
28
28
  throw (0, errors_1.cliError)("COPILOT_SDK_MISSING", "The optional Copilot SDK runtime is not installed.", {
29
29
  installDir: installStatus.installDir,
30
30
  packageName: installStatus.packageName,
31
31
  });
32
32
  }
33
- await (0, copilot_adapter_1.readCopilotAuthState)();
34
- const bridge = await (0, copilot_bridge_1.ensureCopilotBridge)(args.providerName, provider);
33
+ await (0, copilot_adapter_1.readCopilotAuthState)(args.runtimesDir);
34
+ const bridge = await (0, copilot_bridge_1.ensureCopilotBridge)(args.providerName, provider, args.runtimeDir);
35
35
  const nextProvider = bridge.portChanged
36
36
  ? (0, providers_1.cleanProviderRecord)({
37
37
  ...provider,
@@ -44,24 +44,21 @@ async function switchProvider(args) {
44
44
  : provider;
45
45
  try {
46
46
  return (0, run_mutation_1.runMutation)({
47
- codexDir: args.codexDir,
47
+ lockPath: args.lockPath,
48
48
  backupsDir: args.backupsDir,
49
49
  latestBackupPath: args.latestBackupPath,
50
50
  operation: "switch",
51
51
  files: [
52
+ { absolutePath: args.authPath, relativePath: "auth.json" },
52
53
  { absolutePath: args.providersPath, relativePath: "providers.json" },
53
54
  { absolutePath: args.configPath, relativePath: "config.toml" },
54
55
  ],
55
56
  mutate: () => {
56
57
  const configPlan = (0, config_repo_1.createConfigMutationPlan)(document, {
57
58
  setActiveProfile: provider.profile,
58
- upsertModelProviders: bridge.portChanged
59
- ? {
60
- [provider.profile]: {
61
- baseUrl: (0, providers_1.buildCopilotBridgeBaseUrl)(nextProvider.runtime),
62
- },
63
- }
64
- : undefined,
59
+ upsertModelProviders: {
60
+ [provider.profile]: (0, providers_1.buildCopilotModelProviderProjection)(nextProvider.runtime),
61
+ },
65
62
  });
66
63
  if (bridge.portChanged) {
67
64
  (0, providers_repo_1.writeProvidersFile)(args.providersPath, {
@@ -72,6 +69,7 @@ async function switchProvider(args) {
72
69
  });
73
70
  }
74
71
  (0, config_repo_1.applyConfigMutation)(args.configPath, document, configPlan);
72
+ (0, auth_repo_1.writeOpenAiApiKeyAuth)(args.authPath, provider.apiKey);
75
73
  return {
76
74
  provider: args.providerName,
77
75
  profile: nextProvider.profile,
@@ -83,13 +81,13 @@ async function switchProvider(args) {
83
81
  }
84
82
  catch (error) {
85
83
  if (!bridge.reused) {
86
- (0, copilot_bridge_1.stopCopilotBridge)();
84
+ (0, copilot_bridge_1.stopCopilotBridge)(args.runtimeDir);
87
85
  }
88
86
  throw error;
89
87
  }
90
88
  }
91
89
  return (0, run_mutation_1.runMutation)({
92
- codexDir: args.codexDir,
90
+ lockPath: args.lockPath,
93
91
  backupsDir: args.backupsDir,
94
92
  latestBackupPath: args.latestBackupPath,
95
93
  operation: "switch",
package/dist/cli.js CHANGED
@@ -1,10 +1,42 @@
1
1
  #!/usr/bin/env node
2
2
  "use strict";
3
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
+ if (k2 === undefined) k2 = k;
5
+ var desc = Object.getOwnPropertyDescriptor(m, k);
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = { enumerable: true, get: function() { return m[k]; } };
8
+ }
9
+ Object.defineProperty(o, k2, desc);
10
+ }) : (function(o, m, k, k2) {
11
+ if (k2 === undefined) k2 = k;
12
+ o[k2] = m[k];
13
+ }));
14
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
15
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
16
+ }) : function(o, v) {
17
+ o["default"] = v;
18
+ });
19
+ var __importStar = (this && this.__importStar) || (function () {
20
+ var ownKeys = function(o) {
21
+ ownKeys = Object.getOwnPropertyNames || function (o) {
22
+ var ar = [];
23
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
24
+ return ar;
25
+ };
26
+ return ownKeys(o);
27
+ };
28
+ return function (mod) {
29
+ if (mod && mod.__esModule) return mod;
30
+ var result = {};
31
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
32
+ __setModuleDefault(result, mod);
33
+ return result;
34
+ };
35
+ })();
3
36
  Object.defineProperty(exports, "__esModule", { value: true });
4
37
  exports.printHelp = printHelp;
5
38
  exports.printVersion = printVersion;
6
39
  exports.main = main;
7
- const dispatch_1 = require("./commands/dispatch");
8
40
  const args_1 = require("./commands/args");
9
41
  const help_1 = require("./commands/help");
10
42
  const errors_1 = require("./domain/errors");
@@ -49,7 +81,7 @@ function main() {
49
81
  command: parsed.command,
50
82
  options: parsed.globalOptions,
51
83
  };
52
- (0, dispatch_1.executeCommand)(ctx, parsed)
84
+ Promise.resolve().then(() => __importStar(require("./commands/dispatch"))).then(({ executeCommand }) => executeCommand(ctx, parsed))
53
85
  .then((result) => {
54
86
  (0, output_1.outputSuccess)(ctx, result);
55
87
  })
@@ -11,7 +11,7 @@ const registry_1 = require("./registry");
11
11
  */
12
12
  function parseArgs(argv) {
13
13
  let json = false;
14
- let codexDir = (0, codex_paths_1.resolveCodexDir)();
14
+ let codexDir = null;
15
15
  let codexDirExplicit = false;
16
16
  const remaining = [];
17
17
  for (let index = 0; index < argv.length; index += 1) {
@@ -105,7 +105,7 @@ function defaultParsed(command, overrides) {
105
105
  positionals: [],
106
106
  globalOptions: {
107
107
  json: overrides?.json ?? false,
108
- codexDir: overrides?.codexDir ?? (0, codex_paths_1.resolveCodexDir)(),
108
+ codexDir: overrides?.codexDir ?? null,
109
109
  codexDirExplicit: false,
110
110
  },
111
111
  commandOptions: new Map(),
@@ -1,8 +1,44 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
2
35
  Object.defineProperty(exports, "__esModule", { value: true });
3
36
  exports.executeCommand = executeCommand;
37
+ const path = __importStar(require("node:path"));
4
38
  const errors_1 = require("../domain/errors");
5
39
  const prompt_1 = require("../interaction/prompt");
40
+ const codex_paths_1 = require("../storage/codex-paths");
41
+ const tool_config_repo_1 = require("../storage/tool-config-repo");
6
42
  const registry_1 = require("./registry");
7
43
  /**
8
44
  * Resolves the shared command definition and executes its registered handler.
@@ -12,5 +48,9 @@ async function executeCommand(ctx, parsed, runtime = (0, prompt_1.createPromptRu
12
48
  if (!definition) {
13
49
  throw (0, errors_1.cliError)("UNKNOWN_COMMAND", `Unknown command: ${ctx.command}`);
14
50
  }
51
+ const toolHomeDir = (0, codex_paths_1.resolveCodexSwitchHome)();
52
+ const toolConfigPath = path.join(toolHomeDir, "codex-switch.json");
53
+ const toolConfig = (0, tool_config_repo_1.readToolConfigIfExists)(toolConfigPath);
54
+ ctx.options.codexDir = (0, codex_paths_1.resolveCodexDir)(ctx.options.codexDir ?? undefined, toolConfig);
15
55
  return definition.handler(ctx, parsed, runtime);
16
56
  }