generate-child.ts
1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/**
* Child process entry point for service-mode generation.
*
* Why a separate process: generation (especially VALIDATION's Playwright work
* and the multi-agent INITIAL node) is heavy and can crash the whole event
* loop. By running it in a detached child, the `serve` UI process stays alive
* no matter what happens during a run. Logs are forwarded to the parent by
* simply printing to stdout (the parent captures and re-broadcasts them via
* SSE), and a sentinel line marks completion so the parent can flip job state.
*/
import { design2code } from '../graph';
import { ValidationMode } from '../types/graph-types';
import { patchEvoltagentStreamingForceOff } from '../utils/patch-evoltagent';
function mapMode(mode: string): ValidationMode {
if (mode === 'code') return ValidationMode.CodeOnly;
if (mode === 'with-report') return ValidationMode.ReportOnly;
return ValidationMode.Full;
}
async function main(): Promise<void> {
const argv = process.argv.slice(2);
const get = (name: string): string | undefined => {
const i = argv.indexOf(`--${name}`);
return i >= 0 ? argv[i + 1] : undefined;
};
const figmaUrl = get('figmaUrl');
const mode = mapMode(get('mode') ?? 'full');
const outputDir = get('outputDir');
const appName = get('appName');
if (!figmaUrl) {
process.stdout.write('__D2C_ERROR__:missing figmaUrl\n');
process.exit(1);
}
// Force non-streaming agent calls (see patch module).
patchEvoltagentStreamingForceOff();
try {
await design2code(figmaUrl, mode, {
outputDir: outputDir || undefined,
appName: appName || undefined,
resume: false,
});
process.stdout.write('__D2C_DONE__\n');
process.exit(0);
} catch (err) {
const message = err instanceof Error ? err.message : String(err);
process.stdout.write(`__D2C_ERROR__:${message}\n`);
process.exit(1);
}
}
main();