|
| 1 | +# 539 - Todo Fixme Parallel Workflow |
| 2 | + |
| 3 | +```rig |
| 4 | +import { agent, p, s, workflow } from "rig"; |
| 5 | +
|
| 6 | +// Agent role: count TODO comments across the repository. |
| 7 | +const countTodos = agent({ |
| 8 | + model: "small", |
| 9 | + instructions: p`Run ${p.bash("grep -ro 'TODO' src/ | wc -l")} and return the count.`, |
| 10 | + output: s.object({ count: s.int }), |
| 11 | +}); |
| 12 | +
|
| 13 | +// Agent role: count FIXME comments across the repository. |
| 14 | +const countFixmes = agent({ |
| 15 | + model: "small", |
| 16 | + instructions: p`Run ${p.bash("grep -ro 'FIXME' src/ | wc -l")} and return the count.`, |
| 17 | + output: s.object({ count: s.int }), |
| 18 | +}); |
| 19 | +
|
| 20 | +// Agent role: combine TODO and FIXME counts into a total. |
| 21 | +const aggregate = agent({ |
| 22 | + model: "small", |
| 23 | + input: s.object({ todoCount: s.int, fixmeCount: s.int }), |
| 24 | + instructions: "Combine input.todoCount and input.fixmeCount into a total.", |
| 25 | + output: s.object({ todoCount: s.int, fixmeCount: s.int, total: s.int }), |
| 26 | +}); |
| 27 | +
|
| 28 | +// Workflow role: count TODO and FIXME comments in parallel, then aggregate. |
| 29 | +const commentAudit = workflow({ |
| 30 | + meta: { |
| 31 | + name: "comment-audit", |
| 32 | + description: "Count TODO and FIXME comments in parallel and aggregate totals", |
| 33 | + phases: ["Count", "Aggregate"], |
| 34 | + }, |
| 35 | + body: async ({ call, parallel, phase }) => { |
| 36 | + phase("Count"); |
| 37 | + const [todo, fixme] = await parallel([ |
| 38 | + () => call(countTodos, ""), |
| 39 | + () => call(countFixmes, ""), |
| 40 | + ]); |
| 41 | + phase("Aggregate"); |
| 42 | + return call(aggregate, { |
| 43 | + todoCount: todo?.count ?? 0, |
| 44 | + fixmeCount: fixme?.count ?? 0, |
| 45 | + }); |
| 46 | + }, |
| 47 | +}); |
| 48 | +
|
| 49 | +export default commentAudit; |
| 50 | +``` |
0 commit comments