MCPcopy Create free account
hub / github.com/concensure/Semantic / execute_node

Method execute_node

refactor_graph/src/lib.rs:302–386  ·  view source on GitHub ↗
(
        &mut self,
        refactor_id: &str,
        node: &RefactorNode,
        memory: &PatchMemory,
        approved: bool,
    )

Source from the content-addressed store, hash-verified

300 }
301
302 fn execute_node(
303 &mut self,
304 refactor_id: &str,
305 node: &RefactorNode,
306 memory: &PatchMemory,
307 approved: bool,
308 ) -> Result<()> {
309 let target_file_rel = node
310 .edit_plan
311 .required_context
312 .first()
313 .map(|c| c.file_path.clone())
314 .unwrap_or_else(|| "src/refactor_placeholder.ts".to_string());
315 let base = node
316 .repository
317 .as_ref()
318 .map(PathBuf::from)
319 .unwrap_or_else(|| self.repo_root.clone());
320 let target_file = base.join(&target_file_rel);
321
322 self.snapshot_file(refactor_id, &target_file)?;
323 let existing = fs::read_to_string(&target_file).unwrap_or_default();
324
325 if let Some(parent) = target_file.parent() {
326 fs::create_dir_all(parent)?;
327 }
328 let comment_prefix = if target_file_rel.ends_with(".py") {
329 "#"
330 } else {
331 "//"
332 };
333 let patch_marker = format!(
334 "{comment_prefix} refactor_node:{} symbol:{}\n",
335 node.id, node.target_symbol
336 );
337 let transform = edit_type_to_transform(&node.edit_plan.edit_type);
338 let updated = format!("{existing}{patch_marker}");
339 let line_count = existing.lines().count().max(1);
340 let patch = patch_engine::PatchEngine::generate_replacement_patch(
341 &target_file_rel,
342 &existing,
343 patch_engine::LineRange {
344 start_line: 1,
345 end_line: line_count,
346 },
347 &updated,
348 )?;
349 patch_engine::PatchEngine::validate_patch(&target_file_rel, &patch, &existing)?;
350 let diff = match &patch.representation {
351 engine::PatchRepresentation::ASTTransform(edit) => {
352 patch_engine::PatchEngine::ast_to_diff(&target_file_rel, edit)
353 }
354 engine::PatchRepresentation::UnifiedDiff(v) => v.clone(),
355 };
356 fs::write(
357 &target_file,
358 patch_engine::PatchEngine::apply_patch(&existing, &patch)?,
359 )?;

Callers 1

apply_nodesMethod · 0.80

Calls 3

snapshot_fileMethod · 0.80
append_recordMethod · 0.80
edit_type_to_transformFunction · 0.70

Tested by

no test coverage detected