MCPcopy Index your code
hub / github.com/Doorman11991/smallcode / execute_improvement_loop

Function execute_improvement_loop

src/compiled/flows.js:47–95  ·  view source on GitHub ↗
(ctx)

Source from the content-addressed store, hash-verified

45// Flow: improvement_loop
46// ctx must contain: { req, res, auth, client? } for transactional flows
47async function execute_improvement_loop(ctx) {
48 const steps = [
49 {
50 name: "validate",
51 action: async (ctx) => {
52 // Calls capability: validate_file(ctx.file_path)
53 const response = await fetch(`${process.env.SERVICE_BASE_URL || "http://localhost:3000"}/validate-file`, {
54 method: "POST",
55 headers: { "Content-Type": "application/json", "Authorization": ctx.req.headers.authorization || "" },
56 body: JSON.stringify(ctx.req.body),
57 });
58 if (!response.ok)
59 throw new Error(`Step validate failed: ${await response.text()}`);
60 ctx.validate_result = await response.json();
61 },
62 compensation: async (ctx) => {
63 // Compensates: rollback_file(ctx.file_path)
64 await fetch(`${process.env.SERVICE_BASE_URL || "http://localhost:3000"}/rollback-file`, {
65 method: "POST",
66 headers: { "Content-Type": "application/json", "Authorization": ctx.req.headers.authorization || "" },
67 body: JSON.stringify({ ...ctx.req.body, _compensating: true }),
68 });
69 },
70 },
71 {
72 name: "fix",
73 action: async (ctx) => {
74 // Calls capability: fix_code(ctx.file_path, validate.output)
75 const response = await fetch(`${process.env.SERVICE_BASE_URL || "http://localhost:3000"}/fix-code`, {
76 method: "POST",
77 headers: { "Content-Type": "application/json", "Authorization": ctx.req.headers.authorization || "" },
78 body: JSON.stringify(ctx.req.body),
79 });
80 if (!response.ok)
81 throw new Error(`Step fix failed: ${await response.text()}`);
82 ctx.fix_result = await response.json();
83 },
84 compensation: async (ctx) => {
85 // Compensates: rollback_file(ctx.file_path)
86 await fetch(`${process.env.SERVICE_BASE_URL || "http://localhost:3000"}/rollback-file`, {
87 method: "POST",
88 headers: { "Content-Type": "application/json", "Authorization": ctx.req.headers.authorization || "" },
89 body: JSON.stringify({ ...ctx.req.body, _compensating: true }),
90 });
91 },
92 },
93 ];
94 return executeFlow("improvement_loop", steps, ctx);
95}

Callers

nothing calls this directly

Calls 1

executeFlowFunction · 0.70

Tested by

no test coverage detected