(options: {
opts: WorkflowCLIOptions;
projectDir: string;
})
| 275 | } |
| 276 | |
| 277 | async function createWorkflowContext(options: { |
| 278 | opts: WorkflowCLIOptions; |
| 279 | projectDir: string; |
| 280 | }): Promise<WorkflowContext> { |
| 281 | const tempDir = new DisposableTempDir("mux-workflow"); |
| 282 | let services: WorkflowServices | undefined; |
| 283 | let session: AgentSession | undefined; |
| 284 | let codexOauthService: CodexOauthService | undefined; |
| 285 | try { |
| 286 | const realConfig = new Config(); |
| 287 | const config = new Config(tempDir.path); |
| 288 | await copyPersistentConfig(realConfig, config); |
| 289 | |
| 290 | const existingProviders = realConfig.loadProvidersConfig(); |
| 291 | if (!hasAnyConfiguredProvider(existingProviders)) { |
| 292 | const providersFromEnv = buildProvidersFromEnv(); |
| 293 | if (hasAnyConfiguredProvider(providersFromEnv)) { |
| 294 | config.saveProvidersConfig(providersFromEnv); |
| 295 | } |
| 296 | } |
| 297 | |
| 298 | const workspaceId = generateWorkspaceId(); |
| 299 | assert(workspaceId.length > 0, "mux workflow generated an empty workspace id"); |
| 300 | const runtimeConfig = parseRuntimeConfig(options.opts.runtime); |
| 301 | const projectTrusted = await resolveProjectTrusted(realConfig, options.projectDir); |
| 302 | |
| 303 | services = createCoreServices({ |
| 304 | config, |
| 305 | extensionMetadataPath: path.join(tempDir.path, "extensionMetadata.json"), |
| 306 | mcpConfig: realConfig, |
| 307 | }); |
| 308 | codexOauthService = new CodexOauthService(config, services.providerService); |
| 309 | services.aiService.setCodexOauthService(codexOauthService); |
| 310 | |
| 311 | session = new AgentSession({ |
| 312 | workspaceId, |
| 313 | config, |
| 314 | historyService: services.historyService, |
| 315 | aiService: services.aiService, |
| 316 | initStateManager: services.initStateManager, |
| 317 | backgroundProcessManager: services.backgroundProcessManager, |
| 318 | workspaceGoalService: services.workspaceGoalService, |
| 319 | }); |
| 320 | services.workspaceService.registerSession(workspaceId, session); |
| 321 | |
| 322 | const workspacePath = options.projectDir; |
| 323 | await session.ensureMetadata({ |
| 324 | workspacePath, |
| 325 | projectName: path.basename(options.projectDir), |
| 326 | runtimeConfig, |
| 327 | }); |
| 328 | assert(workspacePath.length > 0, "mux workflow workspace path must be non-empty"); |
| 329 | |
| 330 | return { |
| 331 | realConfig, |
| 332 | config, |
| 333 | tempDir, |
| 334 | projectDir: options.projectDir, |
no test coverage detected