MCPcopy Index your code
hub / github.com/Codeplain-ai/codeplain / execute

Method execute

render_machine/actions/refactor_code.py:18–63  ·  view source on GitHub ↗
(self, render_context: RenderContext, _previous_action_payload: Any | None)

Source from the content-addressed store, hash-verified

16 ITERATION_LIMIT_EXCEEDED_OUTCOME = "refactoring_iteration_limit_exceeded"
17
18 def execute(self, render_context: RenderContext, _previous_action_payload: Any | None):
19 if render_context.frid_context.refactoring_iteration == 0:
20 console.info("Refactoring the generated code...")
21
22 render_context.frid_context.refactoring_iteration += 1
23
24 if render_context.frid_context.refactoring_iteration >= MAX_REFACTORING_ITERATIONS:
25 error_message = "Refactoring iterations limit of {MAX_REFACTORING_ITERATIONS} reached for functionality {render_context.frid_context.frid}."
26 render_context.last_error_message = error_message
27
28 return (
29 self.ITERATION_LIMIT_EXCEEDED_OUTCOME,
30 RenderError.encode(message=error_message).to_payload(),
31 )
32
33 existing_files, existing_files_content = ImplementationCodeHelpers.fetch_existing_files(
34 render_context.build_folder
35 )
36
37 console.debug(f"Refactoring iteration {render_context.frid_context.refactoring_iteration}.")
38
39 console.print_files(
40 "Files sent as input for refactoring:",
41 render_context.build_folder,
42 existing_files_content,
43 style=console.INPUT_STYLE,
44 )
45
46 response_files = render_context.codeplain_api.refactor_source_files_if_needed(
47 frid=render_context.frid_context.frid,
48 module_name=render_context.module_name,
49 files_to_check=render_context.frid_context.changed_files,
50 existing_files_content=existing_files_content,
51 run_state=render_context.run_state,
52 )
53
54 if len(response_files) == 0:
55 console.debug("No files refactored.")
56 return self.NO_FILES_REFACTORED_OUTCOME, None
57
58 file_utils.store_response_files(render_context.build_folder, response_files, existing_files)
59
60 console.print_files(
61 "Files refactored:", render_context.build_folder, response_files, style=console.OUTPUT_STYLE
62 )
63 return self.SUCCESSFUL_OUTCOME, None

Callers

nothing calls this directly

Calls 7

infoMethod · 0.80
to_payloadMethod · 0.80
encodeMethod · 0.80
fetch_existing_filesMethod · 0.80
debugMethod · 0.80
print_filesMethod · 0.80

Tested by

no test coverage detected