Skip to content

Commit 86e995f

Browse files
committed
fix: crash on requesting to delete building blocks
1 parent 8d87baa commit 86e995f

3 files changed

Lines changed: 10 additions & 11 deletions

File tree

src/codius/graph/nodes/apply_changes.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,20 @@ def apply_changes(state: dict) -> dict:
2626
deleted_paths = []
2727
for plan_item in state.get("plan", []):
2828
if plan_item["type"] == "delete_directory":
29-
dir_path = Path(plan_item["path"])
29+
dir_path = project_root / plan_item["path"]
3030
if dir_path.exists() and dir_path.is_dir():
3131
shutil.rmtree(dir_path)
3232
deleted_paths.append(dir_path)
3333
elif plan_item["type"] == "delete_file":
34-
file_path = Path(plan_item["path"])
34+
file_path = project_root / plan_item["path"]
3535
if file_path.exists() and file_path.is_file():
3636
file_path.unlink()
3737
deleted_paths.append(file_path)
3838

3939
file_list = "\n".join([
4040
f"✅ {str(f.relative_to(generated_dir))}" for f in generated_files
4141
] + [
42-
f"❌️ {str(p)}" for p in deleted_paths
42+
f"❌️ {str(p.relative_to(project_root))}" for p in deleted_paths
4343
])
4444

4545
state["final_output"] = f"Applied changes:\n\n{file_list}"

src/codius/graph/nodes/preview.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ def preview(state: dict) -> dict:
2222

2323
session_id = state.get('session_id')
2424
generated_dir = metadata_service.get_generated_path(session_id)
25+
project_root = Path(state["project_metadata"]["project_root"])
2526

2627
console = Console()
2728
session = PromptSession()
@@ -41,7 +42,7 @@ def preview(state: dict) -> dict:
4142

4243
# Show deletions
4344
for item in deletions:
44-
file_path = Path(item["path"])
45+
file_path = project_root / item["path"]
4546
if file_path.exists():
4647
try:
4748
content = file_path.read_text()

src/codius/infrastructure/services/code_generator/code_generator_service.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ def __init__(self, convention_service: OpenDddConventionService, tree_sitter_ser
2424
def create_file(self, file_plan: dict, output_dir: Path, project_root: Path) -> Optional[dict]:
2525
template_name = file_plan.get("template")
2626
context = file_plan.get("context", {})
27-
absolute_path = Path(file_plan["path"]).resolve()
28-
relative_path = absolute_path.relative_to(project_root)
27+
relative_path = Path(file_plan["path"])
2928

3029
try:
3130
template = self.jinja_env.get_template(f"{template_name}.cs.j2")
@@ -55,12 +54,11 @@ def modify_file(
5554
project_root: Path,
5655
created_files_map: dict[str, str]
5756
) -> Optional[dict]:
58-
absolute_path = Path(path).resolve()
59-
relative_path = absolute_path.relative_to(project_root)
60-
file_path_str = str(project_root / relative_path)
57+
relative_path = Path(path)
58+
relative_path_str = str(relative_path)
6159

62-
if file_path_str in created_files_map:
63-
current_code = created_files_map[file_path_str]
60+
if relative_path_str in created_files_map:
61+
current_code = created_files_map[relative_path_str]
6462
else:
6563
try:
6664
current_code = (project_root / relative_path).read_text(encoding="utf-8")

0 commit comments

Comments
 (0)