Skill Tracer
Skills › Archify › archify › render-workflow.mjs

render-workflow.mjs

47 lines · archify/renderers/workflow/render-workflow.mjs at a406594

1import path from 'node:path';
2import { fileURLToPath } from 'node:url';
3import { loadDiagramWithBrandMarks, writeDiagram } from '../shared/cli.mjs';
4import { recordDiagnostic, throwDiagnosticError, withIsolatedDiagnosticRecording } from '../shared/diagnostics.mjs';
5import { compileWorkflow } from './workflow-compiler.mjs';
6
7const __dirname = path.dirname(fileURLToPath(import.meta.url));
8const { diagram: workflow, template, outPath, sourceEvidence } = await loadDiagramWithBrandMarks({
9 rendererDir: __dirname,
10 diagramType: 'workflow',
11 defaultExample: 'agent-tool-call.workflow.json'
12});
14let compiled;
15try {
16 compiled = withIsolatedDiagnosticRecording(() => compileWorkflow({
17 workflow,
18 qualityProfile: process.env.ARCHIFY_QUALITY_PROFILE || workflow.meta?.quality_profile,
19 sourceEvidence,
20 }));
21} catch (error) {
22 // The scope has restored the caller's recording. Keep a typed escape visible
23 // alongside earlier failures without publishing abandoned compile attempts.
24 if (Array.isArray(error?.archifyDiagnostics)) {
25 for (const diagnostic of error.archifyDiagnostics) recordDiagnostic(diagnostic);
26 }
27 throw error;
30const layoutJson = process.argv.includes('--layout-json');
32if (layoutJson) {
33 process.stdout.write(`${JSON.stringify(compiled.receipt, null, 2)}\n`);
34 if (!compiled.ok) process.exitCode = 1;
35} else if (!compiled.ok) {
36 throwDiagnosticError(compiled.error || 'Workflow compilation failed.', compiled.diagnostics);
37} else {
38 writeDiagram({
39 outPath,
40 template,
41 diagramType: 'workflow',
42 meta: workflow.meta,
43 svg: compiled.svg,
44 cards: workflow.cards,
45 sourceEvidence,
46 });