( opts: BootstrapRuntimeOptions, )
| 108 | } |
| 109 | |
| 110 | export async function bootstrapRuntime( |
| 111 | opts: BootstrapRuntimeOptions, |
| 112 | ): Promise<BootstrapRuntimeResult> { |
| 113 | process.env.XCODEBUILDMCP_RUNTIME = opts.runtime; |
| 114 | const cwdOverride = opts.cwd === undefined ? resolveCwdOverride() : undefined; |
| 115 | if (cwdOverride !== undefined) { |
| 116 | try { |
| 117 | process.chdir(cwdOverride); |
| 118 | } catch (error) { |
| 119 | log( |
| 120 | 'warn', |
| 121 | `XCODEBUILDMCP_CWD points at "${cwdOverride}" but chdir failed: ${ |
| 122 | error instanceof Error ? error.message : String(error) |
| 123 | }. Falling back to existing cwd.`, |
| 124 | ); |
| 125 | } |
| 126 | } |
| 127 | const cwd = opts.cwd ?? process.cwd(); |
| 128 | const fs = opts.fs ?? getDefaultFileSystemExecutor(); |
| 129 | |
| 130 | const configResult = await initConfigStore({ |
| 131 | cwd, |
| 132 | fs, |
| 133 | overrides: opts.configOverrides, |
| 134 | }); |
| 135 | |
| 136 | if (configResult.found) { |
| 137 | log('info', `Loaded project config from ${configResult.path} (cwd: ${cwd})`); |
| 138 | } else { |
| 139 | log('info', `No project config found (cwd: ${cwd}).`); |
| 140 | } |
| 141 | |
| 142 | const config = getConfig(); |
| 143 | const workspaceIdentity = resolveWorkspaceIdentity({ |
| 144 | cwd, |
| 145 | projectConfigPath: configResult.path, |
| 146 | }); |
| 147 | configureRuntimeWorkspaceKey(workspaceIdentity.workspaceKey); |
| 148 | |
| 149 | if (opts.runtime === 'mcp') { |
| 150 | const hydration = hydrateSessionDefaultsForMcp( |
| 151 | config.sessionDefaults, |
| 152 | config.sessionDefaultsProfiles, |
| 153 | config.activeSessionDefaultsProfile, |
| 154 | ); |
| 155 | logHydrationResult(hydration); |
| 156 | } |
| 157 | |
| 158 | return { |
| 159 | runtime: { |
| 160 | runtime: opts.runtime, |
| 161 | cwd, |
| 162 | config, |
| 163 | }, |
| 164 | workspaceRoot: workspaceIdentity.workspaceRoot, |
| 165 | workspaceKey: workspaceIdentity.workspaceKey, |
| 166 | configFound: configResult.found, |
| 167 | configPath: configResult.path, |
no test coverage detected