diff --git a/src/codius/graph/nodes/apply_changes.py b/src/codius/graph/nodes/apply_changes.py index b40698d..21e0829 100644 --- a/src/codius/graph/nodes/apply_changes.py +++ b/src/codius/graph/nodes/apply_changes.py @@ -26,12 +26,12 @@ def apply_changes(state: dict) -> dict: deleted_paths = [] for plan_item in state.get("plan", []): if plan_item["type"] == "delete_directory": - dir_path = Path(plan_item["path"]) + dir_path = project_root / plan_item["path"] if dir_path.exists() and dir_path.is_dir(): shutil.rmtree(dir_path) deleted_paths.append(dir_path) elif plan_item["type"] == "delete_file": - file_path = Path(plan_item["path"]) + file_path = project_root / plan_item["path"] if file_path.exists() and file_path.is_file(): file_path.unlink() deleted_paths.append(file_path) @@ -39,7 +39,7 @@ def apply_changes(state: dict) -> dict: file_list = "\n".join([ f"✅ {str(f.relative_to(generated_dir))}" for f in generated_files ] + [ - f"❌️ {str(p)}" for p in deleted_paths + f"❌️ {str(p.relative_to(project_root))}" for p in deleted_paths ]) state["final_output"] = f"Applied changes:\n\n{file_list}" diff --git a/src/codius/graph/nodes/preview.py b/src/codius/graph/nodes/preview.py index ebc74ab..f5dd855 100644 --- a/src/codius/graph/nodes/preview.py +++ b/src/codius/graph/nodes/preview.py @@ -22,6 +22,7 @@ def preview(state: dict) -> dict: session_id = state.get('session_id') generated_dir = metadata_service.get_generated_path(session_id) + project_root = Path(state["project_metadata"]["project_root"]) console = Console() session = PromptSession() @@ -41,7 +42,7 @@ def preview(state: dict) -> dict: # Show deletions for item in deletions: - file_path = Path(item["path"]) + file_path = project_root / item["path"] if file_path.exists(): try: content = file_path.read_text() diff --git a/src/codius/infrastructure/services/code_generator/code_generator_service.py b/src/codius/infrastructure/services/code_generator/code_generator_service.py index b179781..1200810 100644 --- a/src/codius/infrastructure/services/code_generator/code_generator_service.py +++ b/src/codius/infrastructure/services/code_generator/code_generator_service.py @@ -24,8 +24,7 @@ def __init__(self, convention_service: OpenDddConventionService, tree_sitter_ser def create_file(self, file_plan: dict, output_dir: Path, project_root: Path) -> Optional[dict]: template_name = file_plan.get("template") context = file_plan.get("context", {}) - absolute_path = Path(file_plan["path"]).resolve() - relative_path = absolute_path.relative_to(project_root) + relative_path = Path(file_plan["path"]) try: template = self.jinja_env.get_template(f"{template_name}.cs.j2") @@ -55,12 +54,11 @@ def modify_file( project_root: Path, created_files_map: dict[str, str] ) -> Optional[dict]: - absolute_path = Path(path).resolve() - relative_path = absolute_path.relative_to(project_root) - file_path_str = str(project_root / relative_path) + relative_path = Path(path) + relative_path_str = str(relative_path) - if file_path_str in created_files_map: - current_code = created_files_map[file_path_str] + if relative_path_str in created_files_map: + current_code = created_files_map[relative_path_str] else: try: current_code = (project_root / relative_path).read_text(encoding="utf-8")