(content: string, relativePath: string)
| 48 | * @returns Parsed config or error |
| 49 | */ |
| 50 | export function parseProcsFile(content: string, relativePath: string): ParseResult { |
| 51 | try { |
| 52 | // Parse TOML |
| 53 | const raw = parseToml(content) |
| 54 | |
| 55 | // Validate with Zod |
| 56 | const parsed = ConfigFileSchema.parse(raw) |
| 57 | |
| 58 | // Transform processes (snake_case -> camelCase, add id) |
| 59 | const processes: ProcessDef[] = parsed.process.map((proc) => ({ |
| 60 | id: `${relativePath}::${proc.name}`, |
| 61 | name: proc.name, |
| 62 | command: proc.command, |
| 63 | workDir: proc.work_dir, |
| 64 | url: proc.url, |
| 65 | type: proc.type, |
| 66 | })) |
| 67 | |
| 68 | // Transform crons (snake_case -> camelCase, add id) |
| 69 | const crons: CronDef[] = parsed.cron.map((c) => ({ |
| 70 | id: `${relativePath}::${c.name}`, |
| 71 | name: c.name, |
| 72 | schedule: c.schedule, |
| 73 | type: c.type, |
| 74 | prompt: c.prompt, |
| 75 | appendSystemPrompt: c.append_system_prompt, |
| 76 | images: c.images, |
| 77 | isolation: c.isolation, |
| 78 | harness: c.harness, |
| 79 | inTaskId: c.in_task_id, |
| 80 | reuseTask: c.reuse_task, |
| 81 | })) |
| 82 | |
| 83 | return { config: { relativePath, processes, crons } } |
| 84 | } catch (e) { |
| 85 | if (e instanceof z.ZodError) { |
| 86 | // Format Zod errors nicely |
| 87 | const firstIssue = e.issues[0] |
| 88 | const path = firstIssue.path.join(".") |
| 89 | return { |
| 90 | error: { |
| 91 | relativePath, |
| 92 | error: `${path}: ${firstIssue.message}`, |
| 93 | }, |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | // TOML parse error |
| 98 | const msg = e instanceof Error ? e.message : "Invalid TOML" |
| 99 | const lineMatch = msg.match(/line (\d+)/i) |
| 100 | return { |
| 101 | error: { |
| 102 | relativePath, |
| 103 | error: msg, |
| 104 | line: lineMatch ? parseInt(lineMatch[1], 10) : undefined, |
| 105 | }, |
| 106 | } |
| 107 | } |
no outgoing calls
no test coverage detected