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

Function runWorkflow

src/cli/workflow.ts:397–462  ·  view source on GitHub ↗
(scriptPath: string, options: WorkflowCLIOptions)

Source from the content-addressed store, hash-verified

395}
396
397async function runWorkflow(scriptPath: string, options: WorkflowCLIOptions): Promise<number> {
398 const projectDir = await resolveProjectDir({
399 cwd: process.cwd(),
400 explicitDir: options.dir,
401 });
402 parseRuntimeConfig(options.runtime);
403
404 const args = await parseWorkflowArgs({
405 arg: options.arg,
406 argsJson: options.argsJson,
407 argsFile: options.argsFile,
408 argsStdin: options.argsStdin,
409 });
410 const model = resolveModelAlias(options.model);
411 const thinkingLevel = resolveThinkingInput(parseThinkingLevel(options.thinking), model);
412 const suppressHuman = options.json === true || options.quiet === true;
413 const writeLine = (line = "") => {
414 if (!suppressHuman) process.stdout.write(`${line}\n`);
415 };
416
417 const ctx = await createWorkflowContext({ opts: options, projectDir });
418 try {
419 const workflowService = createWorkflowService({ ctx, opts: options, model, thinkingLevel });
420 writeLine(`workflow: ${scriptPath}`);
421 writeLine(`directory: ${projectDir}`);
422 writeLine(`runtime: ${ctx.runtimeConfig.type}`);
423
424 const runtime = createRuntime(ctx.runtimeConfig, {
425 projectPath: ctx.projectDir,
426 workspaceName: ctx.workspaceId,
427 workspacePath: ctx.workspacePath,
428 });
429 const script = await resolveWorkflowScript({
430 scriptPath,
431 runtime,
432 workspacePath: ctx.workspacePath,
433 projectTrusted: ctx.projectTrusted,
434 });
435 const result = await workflowService.startWorkflow({
436 script,
437 workspaceId: ctx.workspaceId,
438 projectTrusted: ctx.projectTrusted,
439 args,
440 backgroundOnMessageQueued: false,
441 });
442 if (result.status === "backgrounded") {
443 throw new Error("Headless workflow runs must finish in the foreground");
444 }
445 const run = await workflowService.getRun({ workspaceId: ctx.workspaceId, runId: result.runId });
446 if (options.json === true) {
447 process.stdout.write(
448 `${JSON.stringify({ type: "result", runId: result.runId, status: run?.status ?? result.status, result: result.result })}\n`
449 );
450 } else {
451 const reportMarkdown = extractReportMarkdown(result.result);
452 if (reportMarkdown.length > 0) {
453 process.stdout.write(reportMarkdown);
454 if (!reportMarkdown.endsWith("\n")) process.stdout.write("\n");

Callers 1

mainFunction · 0.85

Calls 15

resolveProjectDirFunction · 0.90
resolveModelAliasFunction · 0.90
resolveThinkingInputFunction · 0.90
createRuntimeFunction · 0.90
resolveWorkflowScriptFunction · 0.90
parseWorkflowArgsFunction · 0.85
createWorkflowContextFunction · 0.85
createWorkflowServiceFunction · 0.85
writeLineFunction · 0.85
extractReportMarkdownFunction · 0.85
disposeWorkflowContextFunction · 0.85
startWorkflowMethod · 0.80

Tested by

no test coverage detected