MCPcopy
hub / github.com/coder/mux / migrateToBackground

Function migrateToBackground

src/node/services/backgroundProcessExecutor.ts:381–412  ·  view source on GitHub ↗
(
  execStream: ExecStream,
  options: MigrateOptions,
  bgOutputDir: string
)

Source from the content-addressed store, hash-verified

379 * @param bgOutputDir Base directory for output files
380 */
381export async function migrateToBackground(
382 execStream: ExecStream,
383 options: MigrateOptions,
384 bgOutputDir: string
385): Promise<MigrateResult> {
386 // Use shared path computation (path.join for local filesystem)
387 const { outputDir, outputPath } = computeOutputPaths(
388 bgOutputDir,
389 options.workspaceId,
390 options.processId
391 );
392
393 try {
394 // Create output directory
395 await fs.mkdir(outputDir, { recursive: true });
396
397 // Write existing output to unified output.log
398 await fs.writeFile(outputPath, options.existingOutput.join("\n") + "\n");
399
400 // Create handle that will continue writing to file
401 const handle = new MigratedBackgroundHandle(execStream, outputDir, outputPath);
402
403 // Start consuming remaining output in background
404 handle.startConsuming();
405
406 return { success: true, handle, outputDir };
407 } catch (error) {
408 const errorMessage = errorMsg(error);
409 log.debug(`migrateToBackground: Error: ${errorMessage}`);
410 return { success: false, error: `Failed to migrate process: ${errorMessage}` };
411 }
412}
413
414/**
415 * Handle for a migrated foreground process.

Callers 1

createBashToolFunction · 0.90

Calls 5

startConsumingMethod · 0.95
computeOutputPathsFunction · 0.85
errorMsgFunction · 0.85
debugMethod · 0.80
writeFileMethod · 0.65

Tested by

no test coverage detected