(ctx: { req: any; res: any; auth: any; client?: any })
| 58 | // Flow: improvement_loop |
| 59 | // ctx must contain: { req, res, auth, client? } for transactional flows |
| 60 | export async function execute_improvement_loop(ctx: { req: any; res: any; auth: any; client?: any }): Promise<FlowResult> { |
| 61 | const steps: FlowStep[] = [ |
| 62 | { |
| 63 | name: "validate", |
| 64 | action: async (ctx) => { |
| 65 | // Calls capability: validate_file(ctx.file_path) |
| 66 | const response = await fetch(`${process.env.SERVICE_BASE_URL || "http://localhost:3000"}/validate-file`, { |
| 67 | method: "POST", |
| 68 | headers: { "Content-Type": "application/json", "Authorization": ctx.req.headers.authorization || "" }, |
| 69 | body: JSON.stringify(ctx.req.body), |
| 70 | }); |
| 71 | if (!response.ok) throw new Error(`Step validate failed: ${await response.text()}`); |
| 72 | ctx.validate_result = await response.json(); |
| 73 | }, |
| 74 | compensation: async (ctx) => { |
| 75 | // Compensates: rollback_file(ctx.file_path) |
| 76 | await fetch(`${process.env.SERVICE_BASE_URL || "http://localhost:3000"}/rollback-file`, { |
| 77 | method: "POST", |
| 78 | headers: { "Content-Type": "application/json", "Authorization": ctx.req.headers.authorization || "" }, |
| 79 | body: JSON.stringify({ ...ctx.req.body, _compensating: true }), |
| 80 | }); |
| 81 | }, |
| 82 | }, |
| 83 | { |
| 84 | name: "fix", |
| 85 | action: async (ctx) => { |
| 86 | // Calls capability: fix_code(ctx.file_path, validate.output) |
| 87 | const response = await fetch(`${process.env.SERVICE_BASE_URL || "http://localhost:3000"}/fix-code`, { |
| 88 | method: "POST", |
| 89 | headers: { "Content-Type": "application/json", "Authorization": ctx.req.headers.authorization || "" }, |
| 90 | body: JSON.stringify(ctx.req.body), |
| 91 | }); |
| 92 | if (!response.ok) throw new Error(`Step fix failed: ${await response.text()}`); |
| 93 | ctx.fix_result = await response.json(); |
| 94 | }, |
| 95 | compensation: async (ctx) => { |
| 96 | // Compensates: rollback_file(ctx.file_path) |
| 97 | await fetch(`${process.env.SERVICE_BASE_URL || "http://localhost:3000"}/rollback-file`, { |
| 98 | method: "POST", |
| 99 | headers: { "Content-Type": "application/json", "Authorization": ctx.req.headers.authorization || "" }, |
| 100 | body: JSON.stringify({ ...ctx.req.body, _compensating: true }), |
| 101 | }); |
| 102 | }, |
| 103 | }, |
| 104 | ]; |
| 105 | return executeFlow("improvement_loop", steps, ctx); |
| 106 | } |
| 107 |
nothing calls this directly
no test coverage detected